0

$USD

$USD
TUTORIALS Raspberry Pi

Raspberry Pi 3 Raspbian: Python Hello World with IDLE

DFRobot Apr 09 2018 1245

In this guide, we will check how to get started with Python on the Raspberry Pi 3, running the Raspbian Operating System. We will use an IDE called IDLE to print our first “Hello World” in Python on the Raspberry Pi. This tutorial was tested on a Raspberry Pi 3 model B+.


Introduction

In this guide, we will check how to get started with Python on the Raspberry Pi 3, running the Raspbian Operating System. We will use an IDE called IDLE to print our first “Hello World” in Python on the Raspberry Pi.

One important thing to mention is that some versions of Raspbian come with two versions of Python installed, namely Python 2.x and Python 3.x. In my case, I’m running version 4.9 of Raspbian, installed using NOOBS, which has both versions of Python included.

We will use the Python 3 version on this tutorial, but if you want to use Python 2 version the procedure will be very similar.

As mentioned, this tutorial was built using version 4.9 of Raspbian, so the location of the tools may be slightly different in other versions.

This tutorial was tested on a Raspberry Pi 3 model B+.

Hello world using IDLE

In order to make it easier to program, most languages have IDEs (Integrated Development Environments), which provide a set of tools to help developing, building and debugging the code.

Python is no exception and has many IDEs available, as can be seen here. Amongst them, IDLE is a very simple IDE which is usually included by default when installing the Python language.

In the case of Raspbian, not only Python is already included, but also IDLE, which we can use right away to start programming in this language.

To open IDLE, go to the main menu and then select Programming. In the list of tools, you should see IDLE for Python 3, as shown in figure 1.


Figure 1 – Opening IDLE.

As soon as you open IDLE, you should get a window with the Python Shell, on the IDE, as illustrated in figure 2.


Figure 2 – IDLE’s Python command line.

There, we can start sending Python commands right away. In our case, we are going to write a simple “Hello World” message, with the following Python code:

print("Hello world from Python on the RPI3!")
After writing the previous command on the Python command line, simply hit enter. You should get a result like figure 3.


Figure 3 – Hello World with Python 3 and IDLE.

Note that you can try this exact same tutorial on Python 2 by opening IDLE for Python two. As it was shown in figure 1, this tool was also listed as available.

The look and feel of the IDE for Python 3 is very similar and the first thing that will open is also the Python Shell, where you can give the same exact command and obtain the same result.

If you are not sure if you start with Python 2 or Python 3, you can read this article, which may give you a help deciding the version to choose.