Using IDLE


IDLE is a code editor and IDE (Interactive Development Environment) that comes with Python. It can be used to enter and run commands in the Python interpreter, and to create Python program files.

It is not required to use IDLE for this course. It is one IDE you may use for coding assignments.

This article demonstrates how to create and run a Python program file. Additional articles can be found on the Internet to learn more about using IDLE; here are two examples:

While IDLE can be used to enter and execute commands in the Python interpreter, the focus here is on using IDLE to create program files that will run in Python.

Creating a Python File

The default IDLE window is empty. This displays a command prompt (>>>) to enter commands.

IDLE Window has Command Prompt

Figure 1: IDLE Window has Command Prompt

The IDLE File menu allows you to create a new file or open an existing file. For a new file, the editor is empty.

IDLE Blank Editor

Figure 2: Create New File in IDLE

Enter your program in the editor window. It is okay to enter a few lines at a time before testing it.

Enter Code in IDLE Editor

Figure 3: Enter Code in IDLE Editor

Save the file using the File menu or CTRL-S.

Save the Python Program as a File

Figure 4: Save the Python Program as a File

To run the program, using the menu or CTRL-F5.

Run the Python Program

Figure 5: Run the Python Program

The program will execute or run in the main IDLE window. Do not confuse this with your program in the editor.

Test the program to see that it runs as expected. Most assignments will provide details on how to test the program (how the Instructor will test it for grading). If that information is available, make sure your program produces the same results as the testing guidelines. Test multiple times!

Figure 6: Test the Python Program

If you make changes to the program, re-save it (using the menu or CTRL-F5) before running it again.

Always run the program to test it before submitting the file for an assignment. The editor saves the program with a .py extension. Submit the .py file for the assignment. (Do not copy/paste IDLE window code or results)