Get startedGet started for free

Using Python packages

Python packages are sort of like the different Toolboxes in MATLAB; however, an important practical difference is that you don't always have access to them in your workspace. Instead, to use a Python package, you must import it explicitly.

You can import an entire package or just import a single function or module from a package. You can also alias a package name to something shorter on import.

# Import a package
import math

# Import a function from a package
from math import log

# Alias a package
import datetime as dt

Let's explore importing with the NumPy package, which lets you store and manipulate multi-dimensional arrays.

This exercise is part of the course

Python for MATLAB Users

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import the NumPy package


# Print the value of pi from the NumPy package
print(____.____)
Edit and Run Code