Open Educational Resources

Python Lab Tutorials: Python Libraries

The following libraries will be covered:

  1. Sympy: a library for symbolic computation where variables are represented as symbols
  2. Numpy: a library for numerical computation using numbers
  3. Scipy: a library that has functions for solving equations numerically, will be covered as a numerical equivalent to Sympy’s solve functions
  4. Matplotlib: a graphing library

Import Library

Libraries are collections of functions that need to be imported. To import a library do one of the following:

  1. import <library>
    1. Imports the entire library. To call a function from the library, use <library>.<function>()
    2. Example: import numpy, then call the function numpy.pi
  2. import <library> as <name>
    1. Imports the entire library as a different name. To call a function from the library, use <name>.<function>()
    2. Example: import numpy as np, then call the function np.pi
  3. from <library> import <function>
    1. Imports only the function from the library and nothing else. To call the function, use <function>()
    2. Example: from numpy import pi, then call the function pi

Leave a Reply

Your email address will not be published.