Note: The screen shots here are from Windows, but the instructions apply to any operating system. You'll first have to download and install Python.
There are two aspects to the Windows Python software. If you double-click .py
files, they will be executed with the Python interpreter directly. A window will appear that runs the program and disappears as soon as it's finished (which often isn't desirable).
If you're working on a program, you should use the Python IDLE (Integrated DeveLopment Environment). This gives a more friendly way to work with Python programs.
Editing a Program
Start Python by running “IDLE (Python GUI)”. This initial window in an \term{interactive interpreter} that can be used to test statement. If you want to actually write a program (that can be saved and submitted), you need to create an editor window in IDLE:
Once you have an editor window, you can write a Python program in it. Note that a program must be saved before you can run it. Here is an example:
To run the program, select “Run” → “Run Module” (or press F5).
The result of running the program (any output or error messages) will be displayed in the original interactive interpreter window:
Interactive Interpreter
It is also possible to type statements directly in the interactive interpreter. When you do this, the statement is executed immediately.
To execute a single statement in the interactive interpreter, it is typed at the >>>
prompt:
>>>
print "Hello world"
Hello world
The interactive interpreter can be used to test statements, but it cannot be used to write a whole program.
If you want to save the code in a .py
file, it must be entered in a editor window, as described above.