Department of Mathematics FAS Harvard University One Oxford Street Cambridge MA 02138 USA Tel: (617) 495-2171 Fax: (617) 495-5132
Python is an interpreted, interactive, object-oriented programming language. For comparisons with other languages, see here. One of the strenghts of Python is that program development using Python is said to be 5-10 times faster than with C/C++ and 3-5 times faster than using Java. < /br>< /br> A nice mathematical library is SciPy. It gives a decent computer algebra system within python:
from scipy.stats import *

from scipy import *
print p*p*p
A = mat('[1 2 3; 4 5 7; 4 1 2]')
b = mat('[1;2;6]')

A = random.rand(5,5)
print linalg.eigvals(A)
A comprehensive Python-based system for mathematics is SAGE by William Stein.

Unlike in Perl you can use it interactively: start by typing "python" and use it as a calculator.
Entering at the python prompt:
for example multiplies two integers (L is needed after the integer for long integers) and finds then 23423.
returns the product of the two complex numbers, or
the absolute value of a complex number.
Most important mathematical functions are predefined. You might to load the math module before using them:
import math
There are many libraries available. For example, to access random numbers, you use
import random
An other library is the calendar:
import calendar
How to work with lists and dictionaries can be seen in How to define functions in or
If a file like is made executable, then it can be called directly The program determines pi=3.14159.... to arbitrary many digits. You could also execute the program by directing in into python. You can also start up python, then type "import" at the python prompt. When looking at , you see the lack of parentheses. This is achieved by text structure. Unlike in other languages, it matters how the indentations are put.
To see an other example, look at, when called for example as "./ 123123" it gives the factorization of the number 123123.
Python allows to write small programs very fast. For example, produces pseudorandom number generators using a quadratic iteration.
An example, of a python program which interacts with the user is the game.
Python is however also used for large projects on the web. The webserver zope for example is written in python.

Links Books
  • Martin C. Brown, Python Annotated Archives, Osborne
  • Mark Lutz, David Ascher, Learning Python

Simplicity, Clarity, Generality B.W. Kernighan, R. Pike, in "The Practice of Programming".