One of Python's great strengths is that it comes with a standard library containing many useful modules. In this lesson, we'll learn the various ways that we can use modules, and we'll also take a look at some of the commonly used modules.
We've already utilized a standard library package when we used the
math module to calculate the circumference of a tire. We used one of the variables from the
math module in the form of
pi, but we loaded the entire module using this line:
import we're able to access the internals of the module, by chaining off of the module's name as we did with
math.pi, but there are other ways we could have accessed
pi. Let's take a look at some of our options:
from math import pi- We can access
piby itself, and we can't reference
mathbecause we used a selective import.
from math import pi as p- This would allow us to have access to a
pvariable that contains the value of
from math import pi, floor, ceil- This would selectively import the
floorfunction, and the
from math import *- This would import EVERYTHING (except names starting with an underscore) from the
mathmodule into the current namespace. Avoid doing this if possible.
Here are some of the most useful standard library modules that we'll use throughout the remainder of the course.