In this tutorial we will check how to print a very simple “Hello World” message with Python running on the command line, on the Raspberry Pi. If you want to learn how to print a “Hello World” message using IDLE, the Python IDE, please check this previous article.
As mentioned in the previous tutorial, some versions of the Raspbian operating system have two versions of Python installed (Python 2.x and Python 3.x, where x is the minor version). You can check more about Python versioning here.
For this tutorial, I’m running version 4.9 of Raspbian, installed using NOOBS, which includes both versions of Python.
So, we are going to check how to run the “Hello World” printing program from the command line in the two versions of Python.
In both cases, the first thing we will need to do is opening the corresponding Python interpreter and then sending the command to print the message.
This tutorial was tested on a Raspberry Pi 3 model B+.
As mentioned, we will need to open the Python interpreter to get started. To do it, simply open a command line and type the following command:
python
After sending the command, it should start the interpreter, a shown in figure 1. Note that, as highlighted, the interpreter lists the whole Python version, including the minor and the micro version.print("Hello World!")
The message should get printed as illustrated in figure 2.
python3
As shown in figure 3, now it will open the Python 3 interpreter. You can confirm that by the version highlighted in the figure.
print("Hello World!")
You should get the same result, as illustrated in figure 4.