Python Tutorials →
In-depth articles and video courses
Learning Paths →
Guided study plans for accelerated learning
Quizzes →
Check your learning progress
Browse Topics →
Focus on a specific area or skill level
Community Chat →
Learn with other Pythonistas
Office Hours →
Live Q&A calls with Python experts
Podcast →
Hear what’s new in the world of Python
Books →
Round out your knowledge and learn offline
Unlock All Content →
If you’ve recently downloaded Python onto your computer, then you may have noticed a new program on your machine called
IDLE
. You might be wondering, “What is this program doing on my computer? I didn’t download that!” While you may not have downloaded this program on your own, IDLE comes bundled with every Python installation. It’s there to help you get started with the language right out of the box. In this tutorial, you’ll learn how to work in Python IDLE and a few cool tricks you can use on your Python journey!
In this tutorial, you’ll learn:
What Python IDLE is
How to interact with Python directly using IDLE
How to edit, execute, and debug Python files with IDLE
How to customize Python IDLE to your liking
What Is Python IDLE?
IDEs
for you to choose from, Python IDLE is very bare-bones, which makes it the perfect tool for a beginning programmer.
Python IDLE comes included in Python installations on Windows and Mac. If you’re a Linux user, then you should be able to find and download Python IDLE using your package manager. Once you’ve installed it, you can then use Python IDLE as an interactive interpreter or as a file editor.
An Interactive Interpreter
interactive interpreter
, otherwise known as a
shell
. The shell is a basic
Read-Eval-Print Loop (REPL)
. It reads a Python statement, evaluates the result of that statement, and then prints the result on the screen. Then, it loops back to read the next statement.
Note:
For a full guide to the standard Python REPL, check out
The Python Standard REPL: Try Out Code and Ideas Quickly
.
The Python shell is an excellent place to experiment with small code snippets. You can access it through the terminal or command line app on your machine. You can simplify your workflow with Python IDLE, which will immediately start a Python shell when you open it.
print()
to output the string
"Hello, from IDLE!"
to your screen. This is the most basic way to interact with Python IDLE. You type in commands one at a time and Python responds with the result of each command.
Next, take a look at the menu bar. You’ll see a few options for using the shell:
You can restart the shell from this menu. If you select that option, then you’ll clear the state of the shell. It will act as though you’ve started a fresh instance of Python IDLE. The shell will forget about everything from its previous state:
In the image above, you first declare a
variable
,
x = 5
. When you call
print(x)
, the shell shows the correct output, which is the number
5
. However, when you restart the shell and try to call
print(x)
again, you can see that the shell prints a
traceback
. This is an error message that says the variable
x
is not defined. The shell has forgotten about everything that came before it was restarted.
You can also interrupt the execution of the shell from this menu. This will stop any program or statement that’s running in the shell at the time of interruption. Take a look at what happens when you send a keyboard interrupt to the shell:
A
KeyboardInterrupt
error message is displayed in red text at the bottom of your window. The program received the interrupt and has stopped executing.
How to Work With Python Files
Code Completion and Call Tips
list
, then you can pause after the opening parenthesis to bring up the call tip:
The call tip will display as a popup note, reminding you how to append to a list. Call tips like these provide useful information as you’re writing code.
Code Context
main function
. When you reach a line that’s outside the scope of this function, the bar will disappear.
How to Debug in IDLE
basic tools
that will help you
debug
your programs with ease!
Interpreter DEBUG Mode
breakpoint
. You’ll learn about these in the next section.
Step:
Press this to execute the current line and go to the next one.
Over:
If the current line of code contains a function call, then press this to step
over
that function. In other words, execute that function and go to the next line, but don’t pause while executing the function (unless there is a breakpoint).
Out:
If the current line of code is in a function, then press this to step
out
of this function. In other words, continue the execution of this function until you return from it.
Be careful, because there is no reverse button! You can only step forward in time through your program’s execution.
You’ll also see four checkboxes in the debug window:
Globals:
your program’s global information
Locals:
your program’s local information during execution
Stack:
the functions that run during execution
Source:
your file in the IDLE editor
When you select one of these, you’ll see the relevant information in your debug window.
traceback
of an error as it appears on the stack of the last error or
exception
that Python IDLE encountered while running your code. When an unexpected or interesting error occurs, you might find it helpful to take a look at the stack. Otherwise, this feature can be difficult to parse and likely won’t be useful to you unless you’re writing very complicated code.
How to Customize Python IDLE
Fonts/Tabs
PEP 8
standard of four spaces. You can change this to make the width of your code more or less spread out to your liking.
extensions
available on the internet for you to read more about. Find the ones you like and add them to Python IDLE!