πŸ“Modules and Packages#

In Python tools are built around modules that perform operations

Modularity allows the isolation of code to simplify programming

Built-in Functions#

Python contains many built in functions

Finding a DataType#

type("Drexel Engineering")
str

You can find more built-in functions

Built-in Modules#

The base package of python contains built-in modules. These have to be imported before they can be used.

You import modules using

import <Module Name>

Random#

We can use random to sample a random integer. This would make a 6-sided die.

import random
dice = random.randint(1,6)
print(dice)
1

You can view everything included in the standard library here

External Packages#

There are many additional packages. Anyone in the world can make a package. Most packages are distributed using the Python Package Index (PyPI).

You can install packages using package managers:

pip install <package name>

or

conda install <package name>

Importing Matplotlib#

A common plotting package in Python is matplotlib, we can import and use matplotlib.

Note

Usually when you download python distributions they will contain many of the common packages. We have installed all the packages you need for the course on the JupyterHub.

Syntax

There are many ways to import packages
import {package name}

from {package name} import {module}

from {package name} import {module} as {name}