Tutorials
python

# Introduction to Python IDLE

Learn what is Python IDLE (Integrated Development and Learning Environment) is, how you can install it, and leverage its various features for writing your Python programs.

If you are just getting started in Python and would like to learn more, take DataCamp's Introduction to Data Science in Python course.

## Introduction

IDLE stands for Integrated Development and Learning Environment. The story behind the name IDLE is similar to Python. Guido Van Rossum named Python after the British comedy group Monty Python while the name IDLE was chosen to pay tribute to Eric Idle, who was one of the Monty Python's founding members. IDLE comes bundled with the default implementation of the Python language since the 01.5.2b1 release. It is packaged as an optional part of the Python packaging with many Linux, Windows, and Mac distributions.

IDLE, as shown above, is a very simple and sophisticated IDE developed primarily for beginners, and because of its simplicity, it is highly considered and recommended for educational purposes. It offers a variety of features that you will look in detail along with examples later in this tutorial.

Some of the key features it offers are:

• Python shell with syntax highlighting,

• Multi-window text editor,

• Code autocompletion,

• Intelligent indenting,

• Program animation and stepping which allows one line of code to run at a time helpful for debugging,

• Persistent breakpoints,

• Finally, Call stack visibility.

## How to Install IDLE?

• One way to install IDLE is to install Python from the officail Python website, as shown below.

You can download the latest Python versions from this website for different operating systems like windows, Linux, and mac. It also provides you the docker images for Python, which you can directly use if you have a docker installed on your system.

Let's install Python for the Windows operating system.

#### Installing Python on Windows OS

• Since Python2 development has been stopped, let's install the latest Python version, i.e., 3.8.2.
• Install the Windows x86 executable installer file depending on whether you have a 32-bit or 64-bit OS and run that file. Once you run the file, a window will open, as shown below. Make sure you select the install launcher for all users and add Python3.8 to Path along with the recommended installation.
• Once the installation is complete, go to the start menu and type idle and click on the same. You should now be seeing the IDLE software on your system.

#### IDLE with Anaconda

IDLE can also be used through Anaconda. If you already have Anaconda installed on your system, just open the anaconda prompt from the start menu and type idle in the anaconda terminal, as shown below.

Since IDLE comes packaged with Anaconda, you will need to download Anaconda from this website.

To learn how to install Anaconda, check out the documentation.

Well, now that you have the IDLE software installed on your respective systems, let's understand its features in detail.

### Exploring IDLE Software Features

• Remember that it is not advisable to write multiple lines of code that have functions/classes in the IDLE shell. In such cases, you can go to the File option of IDLE and click on New File.
• IDLE can be customized using the options present in the Format, Edit, and Options menu.

• ##### Modifying the font-size: Go to the Options menu and click configure idle.

From this, you can choose any font face, font size, make the font bold and even calibrate the indentation width you like working with, as shown below.

IDLE provides you this feature so that each and every person can work with a font size he/she is comfortable working with. A lot of times, your monitor screen size is small, and as a result, you need an IDE that can allow you to increase the font size. That's where IDLE can come into play and give a sense of relief to your eyes.

Not just the font size and style, you can even adjust the indentation, as mentioned before, which is set to 4 spaces by default as per the PEP-8 coding guidelines.

• ### Writing your first code in IDLE

You will write a small program in which you will import the NumPy library, define two arrays, and sum them up. Finally, you will run the code and see the output in the IDLE shell.

To be able to import the NumPy library, make sure it is installed on your system. If not, just go to the command prompt and type pip install NumPy.

#### Call Stack Visibility

While writing the above code, you would notice a dialog box on the screen for both the print function and np.sum function. IDLE will give you the details as to what parameters can be passed to the np.sum function. This is one of the more important and less obvious features of IDLE, which shows the call stack in a verbose manner.

To run the above code, go to the run menu and click on the run module option or directly press F5. It should open the IDLE shell along with the output of your program.

The edit menu in IDLE has a lot of general features like:

• undo,
• redo,
• find,
• find in files,
• replace,
• go to the line,
• show surrounding parenthesis

But one which makes it special is the show completions feature with which you can autocomplete your code. Imagine you are working on a large and complicated project which involves a lot of coding. You might end up spending a lot of time typing the code.

The show complete feature in IDLE helps you in saving typing time by trying to finish the code for you. The Python IDLE is capable of autocompleting only functions and classes. The autocompletion feature can be used by pressing either the tab key or ctrl+space, as shown below:

You already saw the Fonts/Tabs feature, now let's look at some more features in configure_idle under the options menu.

• Highlights: Here, you can change the color of the code syntax according to your preference and not just that. You can also configure idle to work in dark mode or theme, which is a great feature to have, especially when you want to code for longer duration and give some relief to your eyes.

By default, idle works in classic mode and can be tuned to work in a dark mode.

#### Idle in Dark Theme!

• Keys: This feature lets you map different key presses to actions, also known as keyboard shortcuts. These are vital components to increase your overall productivity while using an IDE. You can either come up with your own keyboard shortcuts or use the default ones.

As can be seen from the below figure, the keys are represented in the Action - Key format, which shows you the action that is performed when a specific key or keys are used. Though rarely used by developers, the keys feature in IDLE makes your life easier, especially when you want to write a lot of code in a quick manner.

Like other menu's, Format also has few useful features like indent region, dedent region, comment out a region, etc.

Let's look at the indent region. The indentation in Python is used to segregate a block of code, let's say you have written a code but missed giving indentations to it, the indent region feature could come to your rescue.

The ident region tab added 4 spaces to the selected lines of code, as shown below:

Similarly, the dedent region will help you in removing any unnecessary spaces from your code.

#### Writing a Palindrome Code in IDLE

A palindrome is a word, phrase, or sequence of numbers that read the same backward as forward.

For example, sequence 121, 151, etc.

Let's quickly write the Palindrome code in IDLE and check the output.

Let's now save the above code and run it.

From the above output, you can observe that in all four experiments, the program expected input from the user, and based on the input, the if-else conditions were executed.

## Conclusion

Congratulations, you have made it to the end of this tutorial!

In this tutorial, you've learned about Python IDLE, how to install it, and various features associated with it. Since now you are familiar with IDLE's features and capabilities, it would be much easier for you to start using it.

Those of you who have just started to learn Python, IDLE would be the best development environment for you to get your hands dirty by starting to code in it.

If you are just getting started in Python and would like to learn more, take DataCamp's Introduction to Data Science in Python course.