Getting started

Python is from the command-line oriented world.
Open a terminal window, and type the command python
If it's in your path, you'll now be in the Python interpreter.


/home/dave> python
Python 2.2.2 (#1, Mar 17 2003, 15:17:58)
[GCC 3.3 20030226 (prerelease) (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 1 + 1
>>> print x
2
>>>



The " >>> " is the Python prompt. You type commands following the prompt.
A " ... " is the secondary prompt, which you'll see when entering more complex (multi-line) commands.

>>> if 1 + 1 == 2:
...     print 'it works'
...
it works
>>>



To exit Python, hit Ctrl-D at the >>> prompt.
(In Windows, use Ctrl-Z + Return.)

An alternative way to exit is to type the command:

import sys; sys.exit()



Scripts

To create a Python script, put the Python code in a text file (using any text editor), and then pass it as the command line argument to python.
e.g.:

/home/dave> vi helloworld.py
/home/dave> python helloworld.py
Hello, world


next