Mythology

The first great achievement of Apollo was to slay the huge serpent Python. In some texts
Python is an enormous dragon and not a serpent.
But who was this mythical creature? Python was created out of the slime and mud left after
the great flood. She was appointed by Gaia (Mother Earth) to guard the oracle of Delphi,
known as Pytho. After having defeated Python Apollo remade
her former home and the oracle as his own.

Quote of the Day:

"For instance, on the planet Earth, man had always assumed that he was more intelligent than dolphins because he had achieved so muchâthe wheel, New York, wars and so onâwhilst all the dolphins had ever done was muck about in the water having a good time. But conversely, the dolphins had always believed that they were far more intelligent than manâfor precisely the same reasons" (Douglas Adams, The Hitchhiker's Guide to the Galaxy)

If you have the choice working with Python 2 or Python 3, we recomend to switch to Python 3!
You can read our Python Tutorial to see what the differences are.

Using the Python Interpreter

With the Python interactive interpreter it is easy to check Python commands.
The Python interpreter can be invoked by typing the command "python" without any
parameter followed by the "return" key at the shell prompt:

Once the Python interpreter is started, you can issue any command at the command
prompt ">>>".
The first thing we will do is write the mandatory "Hello World" statement:

>>> print "Hello World"
Hello World

It couldn't have been easier, could it? Oh yes, it can be written in a even simpler
way. In the interactive Python interpretor the print is not necessary:

>>> "Hello World"
'Hello World'
>>> 3
3
>>>

In the following example we use the interpreter as a simple calculator by typing an
arithmetic expression:
>>> 4.567 * 8.323 * 17
646.18939699999999
>>>
You might be surprised, if you type in the following:

>>> 12 / 7
1
>>>

Python assumes that you are interested in integer division, because both divisor and
dividend are integers. So the result is an integer again. The easiest way to get an exact
result is by making one of the values a float by adding a ".0":

>>> 12.0 / 7
1.7142857142857142
>>>

Alternatively you can cast one or both arguments:

>>> float(12) / 7
1.7142857142857142
>>>

Python follows the usual order of operation in expression. The standard order of operations
is expressed in the following enumeration:

exponents and roots

multiplication and division

addition and subtraction

This means that we don't need parenthesis in the expression "3 + (2 * 4):

>>> 3 + 2 * 4
11
>>>

The most recent output value is automatically stored by the interpreter in a special
variable with the name "_". So we can print the output from the recent example again by
typing an underscore after the prompt:

>>> _
11
>>>

The underscore can be used in other expressions like any other variable: