How to run a program in Python IDLE
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.
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.
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.
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.
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.
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.
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.
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.
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.
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:
- How to use the Python for loop
- How to use Python Sets
- How to use a Python Dictionary
- How to use Python Classes
- How to use Python Range
- How to use Python if-else statements
- How to use Python RegEx
- How to use Python Lists
- How to use Python Enumerate
- How to use Python Functions
- How to use Python Split
- How to use Python Try-Except
- How to use Python Tuples
- How to use Python Arrays
- How to use Python Sort
- How to use the Python DateTime
- How to download Python?
- How to use the Python FileWrite function
- How to use Python Lambda
- How to use Python ListAppend
- How to use Python ListComprehension
- How to use Python Map
- How to use Python Operators
- How to use Python Pandas
- How to use Python Requests
- How to use Python Strings
- How to use Python Count
- How to use Python Comments
- How to use the Python File Reader method
- How to use the Python IDE-s
- How to use Python logging
- How to use Python Print
- How to use the Python Zip
- How to use Python Append
- How to use Python Global Variables
- How to use the Python join method
- How to use Python list length
- How to use Python JSON files
- How to use Python Modulo
- How to use Python file opening methods
- How to use Python round
- How to use Python sleep
- How to use Python replace
- How to use Python strip
- How to use the Python Time module
- How to use Python unittests
- How to save data to a text file using Context Manager?
- How to use Python external modules
- How to use Python find
- How to install the Python pip package manager
- How to delete files in Python
- Parsing XML files in Python
- How to make a GUI in Python
- How to use Python in Command Prompt
- How to Run a Python Program in VS Code
- How to run a program in Python IDLE
- How to run a program in Jupyter Notebook
- How to read a text file in Python
- How to add numbers in Python
- How to ask for user input in Python
- How to debug in Python
- How to create a thread in Python
- How to import a library in Python
- How to use the PIP package manager
- How to use classes in Python
- How to reverse strings in Python
- How to convert a string to int in Python
- How to print on the same line in Python
- How to remove items from a list
- How to add to a dictionary in Python
- How to raise an exception in Python
- How to throw an exception in Python
- How to stop a program in Python
- How to use Python assert
- How to use the Python compiler
Would you like to learn how to code, online? Come and try our first 25 lessons for free at the CodeBerry Programming School.
Learn to code and change your career!

100% ONLINE

IDEAL FOR BEGINNERS

SUPPORTIVE COMMUNITY

SELF-PACED LEARNING
Not sure if programming is for you? With CodeBerry you’ll like it.
