Once you open IDLE, the first thing you see is the “IDLE Shell” window, as shown in Figure 1.
Notice: To open IDLE on Linux, type into the terminal “idle” or “idle3” without the double quotes.
IDLE Shell is an environment where you can type statements that are immediately executed. For example, if you type 7 + 3 and hit the “Enter ⤶” key, the IDLE Shell will directly display the result of this addition.
However, you must not write a Python program within the “IDLE Shell” window. To write a Python program, create a new Python file (known as a Python “module”). From IDLE Shell’s main menu select “File → New File” as shown in Figure 2.
Notice: In simple terms, a “module” is a file containing Python code. Its filename is the module name followed by the .py file extension.
A new window opens, as shown in Figure 3. This is a new empty module where you will write your Python programs!
You have just seen how to create a new Python module. In the recently created window “untitled”, type the following (terrifying, and quite horrifying!) Python program.
print("Hello World")
Now let’s try to execute the program! From the main menu, select “Run → Run Module” as shown in Figure 4, or hit the F5 key.
IDLE prompts you to save the source code. Click on the “OK” button, select a folder and a filename for your first program, and click on the “Save” button. The Python program is saved, executed, and then the output is displayed in the IDLE Shell window, as shown in Figure 5.
Congratulations! You have just written and executed your first Python program!
Now let’s write another Python program, one that prompts the user to enter their name. Type the following Python program and hit F5 to execute the file.
name = input("Enter your name: ")
print("Hello", name)
print("Have a nice day!")
Remember! You can execute a program by selecting “Run → Run Module” from the main menu, or by hitting the F5 key.
Once you execute the program, the message “Enter your name: ” without the double quotes is displayed in the IDLE Shell window. The program waits for you to enter your name, as shown in Figure 6.
Type your name and hit the “Enter ⤶” key. Once you do that, your computer continues to execute the rest of the statements. When execution finishes, the final output is as shown in Figure 7.