Using Python Packages

This lesson gives a brief overview of Python packages.

Importing packages #

Python allows developers to group related functions into hierarchical namespaces like packages, modules, etc.

When we want to use a module, class, or function from a package, we need to import it. There are many different ways to import packages. The most basic syntax is:

import numpy

after which any relevant module, class or function in that package inside numpy can be called as numpy.function().

Some packages also have sub-packages with specialized functions. For example, the numpy package has a subpackage called random, which has a bunch of functions that deal with random variables.

numpy also has a sub-package linalg, which has a bunch of functions for linear algebra.

Get hands-on with 1200+ tech skills courses.