First page Back Continue Last page Overview Graphics

Python Modules

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.

The following is saved in fibo.py:

def fib(n):

a, b = 0, 1

for i in range(n):

a, b = b, a + b

return a

def fiblist(n):

fib = [0,1]

for i in range(1,n):

fib += [fib[-1]+fib[-2]]

return fib