Modules

  • A module is a way for python to bundle together a set of several functions and statements
  • You can then import these modules into programs and use them
  • A module is usually made of a set of tools that are used for a single type of task

In [ ]:
import math

In [ ]:
math.log10(200)

In [ ]:
math.pi

In [ ]:
math.degrees(math.pi/2.0)

In [ ]:
import matplotlib.pyplot as plt
%matplotlib inline

In [ ]:
xvals = [0.5, 1, 2.5, 3, 3.1]
yvals = [1,5,2,3,0]
xvals2 = [1,2,3,4]
yvals2 = [1,2,3,4]

plt.plot(xvals,yvals,'r-',xvals2,yvals2,'b--',linewidth=3)
plt.axis([0,4,-1,6])
plt.title("clever title")
plt.xlabel("time")
plt.ylabel("some values")
plt.savefig("my_first_figure.pdf")

what have we learned?

  • People have written all sorts of useful tools for python
  • Modules are a way to access this, by typing "import modulename" or a variant
  • The Python math module and matplotlib.pyplot are two examples of python modules
  • pyplot lets make and modify figures in all sorts of useful ways

In [ ]: