Python online tutorial

Part 3: IDLE

IDLE stands for Integrated Development and Learning Environment. It is a tool designed to aid Python programmers in their task, and provides many useful features.

  • It is designed with education in mind and as thus is simple and suitable for beginners.
  • It will automatically highlight Python code in different colours so you can tell the difference between various syntax elements.
  • It will indent code for you – indentation in Python is extremely important, as it’s the only way for the computer to know what code corresponds to what block.

This is what you see when you fire up IDLE:

As you can see, the cursor appears after the sequence >>>. This informs you that you are currently at a Python interpreter or shell. The interpreter is simply a user interface which you can use to access functionality – in this case, it will let you use various predefined commands, execute simple arithmetic and define functions and variables which are stored only as long as the interpreter is open. Try it out: If you type 6+4, you should see it outputs 10. You can also type help() for some useful info.

blank

However, this is not the most important part of IDLE. If you use the Python interpreter to make a Python program, your work will be lost as soon as you close it – what we want is to write a program in a separate file, so that we can update or run it whenever we want to. Python files have the extension .py, and they’re sometimes called “modules” (you’ll see why you need to know that in no time). To create a new Python file, just go to File > New File. That should bring up something that looks like this:

blank

Well done, you’ve created your first Python file. At the moment, it does absolutely nothing – you can check this by running the module, using Run > Run Module. Every time you run a program, your shell (in a separate window) will display the output of that program. Before you do anything else, save the file by going to File > Save. I’ve saved mine as tutorial.py.

blank

Now let’s try making things a bit more interesting. The print statement is one of the easiest to learn. It just prints whatever information you give it to the console. Why don’t you try printing Hello World? Here’s the code you need to put in your file:

print("Hello World")

The parentheses ( and ) are important, as they enclose the arguments you are passing to the print function. The double quotes " delimit a string (more on this later). Now, check your output. You should see this:

blank

Congratulations – your first Python program is complete. You will get more familiar with IDLE as you go – remember, the most important part of programming is practice, practice, practice!