Session Ready
Exercise

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.

Instructions 1/3
undefined XP
  • 1

    Import numpy and print the value of the numpy constant pi.

    • 2

      Import numpy again, but this time assign it to np, then print pi.

    • 3

      Only import pi from the numpy package.