Python is a general purpose interpreted language which has several major advantages for math and science users. Python is freely available, is pre-installed on most UNIX/OSX/Linux systems, and has features (packages, operator overloading) which lend themselves to the mathematics user. It is an interpreted language, so it can be used like a calculator for simple computations.
Python is free and can be easily installed on most computer systems. Downloads
are available from the Python home page [
Python is pre-installed on UNIX/OSX/Linux systems. It is thus available in computer labs,
on remotely accessible servers and on home machines.
The classic way to use Python is as a command line application.
Recently there have been ways made available to write and run simple examples of Python code from within a web page.
At the Python command prompt (which usually looks something like
type the command to be run, and then press the
Return key to have Python run the
command. As a simple example, if you want to add two integers type:
3 + 12
Intermediate values can be saved by giving them a name and assigning them a value with the
= operator. If the following two commands are run the second output will be the
thesum = 3 + 15
thesum - 14
Python is very careful about exact integer values. Thus the quotient
returns a value of 2. If a decimal (aka floating point) value is wanted one of the operands
can be written in that form, so
12.0/5 returns a value of 2.3999 (which is
When you are done with Python, hold down the Control key and type
The most authoritative and up-to date source for Python documentation is on the Python home page at [http://docs.python.org/]. Particularly useful for the beginner are the various tutorials listed at [http://wiki.python.org/moin/BeginnersGuide]. The basic Python commands are documented at [http://docs.python.org/library/functions.html].
Other references include:
http://www.diveintopython.net/] (also in print form)
http://www.greenteapress.com/thinkpython/] (also in print form)
When working with Python you can move in a line using the usual left and right arrow keys. Earlier commands can be recalled with the up arrow key. If you are familiar with the simple Emacs commands you can use them as well.
If a file contains python commands they can be executed either from the UNIX command line or from within a Python session:
% python myfile.py- Will run the python code in the file myfile.py from the UNIX command line.
>>> execfile("myfile.py")- Will run the python code in the file myfile.py from the Python command line.
A more flexible way to import Python commands into a session is with the
A small collection of my warranty-free, freely-usable Python math libraries.