Python programs are created in the form of files. By convention, the name of the file that contains a Python program has the extension .py.

Most Python installations (definitely those for Windows and Mac OS) also install an environment to create programs in, which is called IDLE. They usually also create some access point for the IDLE environment (for instance, and icon or link on the desktop or in a program menu). IDLE is a quite bare, but suitable environment to do your programming in.

IDLE

The IDLE environment.

When you start IDLE, you are in a so-called “Python shell” (see Figure 3.11) This is, as it were, an interactive Python program, in which you can type lines of Python code, which are run immediately. For instance, if you type print(7/4), IDLE will show you the answer \(1.75\). In general, this is not how you wish to create and run code, but you can use the shell to quickly test the effect of Python statements.

To write Python programs with IDLE, you can create new Python files, or open existing Python files, using the “File” menu. IDLE then gives you a new window in which you can write code, edit code, and save code. You can even run the code immediately from this window, using the “Run” menu (there is a shortcut key to immediately run the program, usually F5). The program then actually runs in the shell, so that is where you supply input and can see the output. Make sure that you save your programs with a name that ends in .py.

There are user-friendlier ways to create Python programs. What you need is a text editor, preferably one that supports writing Python code specifically. Note that a text editor is different from a word processor; a text editor has no formatting options. You might see text getting formatted while typing in a text editor, with bold, italics, and colors, but this is so-called “syntax highlighting,” which shows for a particular programming language how certain words that you type are understood by the program.

There are many text editors available that support writing Python code, for many different operating systems, most of them free. If you are unhappy with IDLE to write code, you can search for alternatives on the Internet. All editors have their own advantages and disadvantages, so what you prefer to use is up to you.