tutorials.neonphog.com icon

python - Intro

Getting Python Starting the Interpreter Testing Getting Out

Getting Python

You can download python from www.python.org. You can also find documentation regarding how the language works, and how to use the libraries that come with the language. Once again, I would recommend getting version 2 if you wish to follow along with this tutorial.

Linux

If you are using linux, chances are you already have python installed. If you want to build it from source, it is as simple as "./configure && make && make install".

Windows

If you are using Windows, simply follow the download links to the Windows installer, and run it to install python.

Starting the Interpreter

To start the python interpreter, simply type "python" on the command line (or in Windows, run the interpreter from your start menu). You should see a screen similar to this:

$ python
Python 2.5.2
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits", or "license" for more information
>>>

Those three angle brackets ">>>" mean you are inside the python interpreter. Anything you type will be run as though it were a line in a program being executed by python.

Testing

Let us start with something simple. Type the following into the interpreter, and press return.

print "Hello World"

The print keyword will take anything you pass it, in this case a string, and display it to the user. You should see something like this:

>>> print "Hello World"
Hello World
>>>

Congratulations! You've just run a line of python code.

Getting Out

To leave the interpreter, if you are using Windows, use Ctrl-Z. If you are using linux, use the more appropriate Ctrl-D to exit.

Next up, we will create an actual source file and run it: Hello World

tutorials home python home