IDLE is an alternative method to using a text editor to write, execute, and test a Python program

IDLE is a cross-platform  Integrated Development and Learning Environment which is the same in both Windows, Unix and macOS.

The Python IDLE has two main windows that can be opened concurrently and that is the Shell window and the Editor window. It is also possible to open two editor windows at the same time. In this article, we’ll show you how to run a program in Python IDLE.

What is Python Shell used for?

Now the Python shell is more like the windows command prompt, however it has additional features such as syntax highlighting and automatic indentation. This makes it easier to use.

In addition to this, both the Editor window and shell window can be exploited at the same time by writing code in the editor window and running the code in the shell window as we would shortly see in an example.

IDLE is an alternative method to using a text editor to write, execute, and test a Python program

How to run a program in Python IDLE – Example 1

The Python shell window can also be accessed by opening the windows command prompt and typing the word python.

IDLE is an alternative method to using a text editor to write, execute, and test a Python program

The Python IDLE can also be configured using the options menu at the top of the window. For example, we can change the theme of the IDLE to black by navigating to the Configure IDLE option under the options menu and then clicking the highlights tab.

How to run a program in Python IDLE – customization

Now to change the theme we can click on the tab labelled IDLE Classic on the far right and change it to IDLE Dark.  In addition to this, we can also change the font colour and also font size.

IDLE is an alternative method to using a text editor to write, execute, and test a Python program

Using the Editor window and Shell window simultaneously

As we had mentioned before the Editor window and the Shell window can be used at the same time.

Using the interactive shell we can run commands that can be executed right away, on the other hand using the Editor window we have opened a python file named ‘test.py’.

Now that we have both windows opened we can start working on some Python code.

IDLE is an alternative method to using a text editor to write, execute, and test a Python program

Create a for loop in Python IDLE

Now using the Python shell on the left-hand side we are going to create a list of numbers and a for loop that will iterate through the list.

The syntax highlighting the feature and automatic indentation can be seen while typing this code in the Python shell.

IDLE is an alternative method to using a text editor to write, execute, and test a Python program

How to run a program in Python IDLE – Example 3

Once we hit the enter button twice the code is executed promptly. On the other hand, we can write this code in the Editor window and run it on the shell window.

Therefore instead of creating the list on the Shell windows, we are going to create the nums list and the for loop on the Editor window and save it.

Now to run this code on the Shell window, we need to make sure the code has been saved in the Editor window.

IDLE is an alternative method to using a text editor to write, execute, and test a Python program

How to run a program in Python ILDE – Example 2

Now to execute this file click on the  Run option on the menu and select Run Module. Alternatively pressing the F5 button on a Windows machine will do the same.

Now in the shell window, you’d notice that it did restart the shell, this means that we would still have access to the nums variable even though the shell restarts again.

IDLE is an alternative method to using a text editor to write, execute, and test a Python program

Create a function in Python IDLE

We would like to explore the functionality of these two windows further by creating a function that will work with the for loop we have just created.

Instead of just iterating through the list and printing out its components, we are going to define a function that will take each of the numbers in the list and add 5 to it.

The function takes in two arguments one of the arguments will be from the elements in the list while the other argument is the number 5.

IDLE is an alternative method to using a text editor to write, execute, and test a Python program
 

Similarly to execute the code above click the Run option on the menu at the top of the Editor window and select the option Run Module, alternatively press the F5 button

This method is particularly suitable for beginners who are using and learning the Python programming language for the first time.

IDLE is an alternative method to using a text editor to write, execute, and test a Python program

Summary

This is how to run a program in Python IDLE. If you’d like to see more programming tutorials, check out our Youtube channel, where we have plenty of Python video tutorials in English.

In our Python Programming Tutorials series, you’ll find useful materials which will help you improve your programming skills and speed up the learning process.

Programming tutorials:

Would you like to learn how to code, online? Come and try our first 25 lessons for free at the CodeBerry Programming School.

IDLE is an alternative method to using a text editor to write, execute, and test a Python program

IDLE is an alternative method to using a text editor to write, execute, and test a Python program

IDLE is an alternative method to using a text editor to write, execute, and test a Python program

IDLE is an alternative method to using a text editor to write, execute, and test a Python program

TRY THE FIRST LESSONS FOR FREE

IDLE is an alternative method to using a text editor to write, execute, and test a Python program