The Python interpreter followed the print command and and displayed whatever text appeared between the quotation marks on the next line. A line of code like this that has a command and some data is called a statement. Python interpreted the statement and displayed the result on the next line. Running Python this way is called interactive mode and it is a good way to testing code a single statement at a time. However if you want to run more complex code or you just want to save your code, you will need to write Python scripts. Here is how to create a Python script:
1. From the IDLE window's File menu select New Window.
2. In the new window write your code as follows:
#Hello world program (Python ignores lines starting with #)
print "Hello World!"
3. From the New Window's File menu select Save As... and save the program anywhere you wish with whatever name you like just so long as the name has the extension .py.
4. You may run the program in either of two ways:
- From the Run menu of the New Window select run.
- Run the program directly from the directory where you saved it.
5. Windows users will see a blur if they run this program directly from the folder were it is saved because it exits as soon as it has run. To remedy this, add the following line to the end of the program. This line of code tells the program to wait for input from the keyboard:
raw_input("\n\nPress the enter key to exit.")