Lesson 2 - IDLE and the first Python console application

Python Basics IDLE and the first Python console application

In the previous lesson, Introduction to the Python language, we talked about the Python language itself. In today's lesson, we're going to focus on IDLE. We'll show you how to use it and program a simple console application.

IDLE stands for Integrated DeveLopment Environment and it comes with Python. In a nutshell, it's an application that lets us write code, and then use it to run, test and debug our applications.

Of course, we'll have to start by installing Python. You can download it on the official site - https://www.python.org/downloads/. Keep in mind that we're going to work with Python 3.

Installation

Download Python 3.X from the Download section and run the installer.

Downloading the Python programming langage and IDLE

Once you run the file, the installation wizard will execute. Check the "Add Python 3.X to PATH" which will register the interpreter to your command line and make running your future projects easier. Aside from that, we'll get by with the express installation - click "Install Now".

Installing Python on Windows

Backup and version control

Programmers usually need a tool that provides version control and backup of their work. We can't rely on the fact that we could simply save the program because we're humans and humans make mistakes. When you lose a few days' or even a few weeks' work, it can be really demotivating. It's good to think about this sort of situation right from the start. I highly recommend Dropbox, which is extremely simple, and automatically stores multiple versions of your files, which makes it possible to revert to previous versions of the project, and also synchronizes with a web repository. Even if you've accidentally deleted your project, overwrote it, somebody stole your laptop or your hard drive accidentally collapsed, your data will remain safe. Dropbox also allows you to share projects with several developers. You can download Dropbox at https://www.dropbox.com.

You can also use a tool called GIT for the same purposes, but its configuration would require the "while" article. Dropbox is perfect for our current intents and purposes.

The Shell

Now, let's run IDLE. Since the installation didn't add a shortcut to our Desktop, enter the "Start" menu and type "IDLE". Then, click on the search result with the right mouse button and choose "Pin to Taskbar".

IDLE taskbar shortcut in Windows

You can now start IDLE by clicking on the Taskbar icon. The first run might take some time.

Python IDLE in Windows Taskbar

You should now see the Python Shell window. It's a terminal through which we can send commands to the Python interpreter. It also displays the outputs.

Hello world

As tradition instructs, we'll make the first program most people make when they learn a new language - Hello World. This is a program that displays "Hello world" or some similar text.

Let's call a function that prints out text, as you may have expected, it's called print(). Some functions require input parameters. In this case, print() requires the value to be printed as a parameter. We specify function parameters in the parentheses after the function name. In Python 3, we always write parentheses (even if the function doesn't require any parameters). This is a major difference when compared to the older Python 2.

Write the following into IDLE and press enter:

print("Hello world")

In programming, texts are called strings, like a string of characters, and are written in quotation marks. Python sees the quotation marks and interprets it as text. Without the quotes, the text could easily be misinterpreted with other language commands. We can use both double or single quotes.

The result should look like this:

Python IDLE

By the way, you can use the Python console as an advanced calculator. Try entering math problems like:

10 * 20

Console application
200

Creating a project

Ok, this was interesting but we'd like to create actual programs instead of sending commands through the console. Click on "File" in the IDLE application menu and select "New File".

A new Window will appear. Now, let's write the Hello world program again. This time, in a separate project file.

#!/usr/bin/python3

print("Hello ICT.social")
print("We'll learn more in the next lesson!")

The first line is optional but it's better to introduce it. It is designed to help run the script on some systems since it specifies the Python version.

Let's save our script by pressing CTRL + S or (File -> Save) from the application menu. If you decided to use Dropbox, create a new folder in your Dropbox folder (C:\uses\your_u­sername\Dropbox), e.g. python. We'll name our first program "hello.py".

You can run the program by pressing F5 or (Run -> Run Module) from the application menu.

The result:

Console application
Hello ICT.social
We'll learn more in the next lesson!

Congratulations, you have just become a programmer :) That will be all for today. In the next lesson, Variables, type system and type conversions in Python, we'll look at the basic data types and create a simple calculator.

Today's project is attached as a file at the end of the article. You can always download the result below each lesson. I suggest that you create a project using the tutorial, and if something in your project doesn't work, then download it to find a mistake. If you download the lesson code before even trying to make it yourself, you won't learn anything :)


 

 

Article has been written for you by David Capka
Avatar
Do you like this article?
No one has rated this quite yet, be the first one!
The author is a programmer, who likes web technologies and being the lead/chief article writer at ICT.social. He shares his knowledge with the community and is always looking to improve. He believes that anyone can do what they set their mind to.
Unicorn College The author learned IT at the Unicorn College - a prestigious college providing education on IT and economics.
Activities (4)

 

 

Comments

To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

No one has commented yet - be the first!