The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1

94 THE OFFICIAL RASPBERRY PI BEGINNER'S GUIDE


Your first Python program: Hello, World!
Like the other pre-installed programs on the Raspberry Pi, Thonny is available from the menu:
click on the raspberry icon, move the cursor to the Programming section, and click on Thonny.
After a few seconds, the Thonny user interface (Simple Mode by default) will load.
Thonny is a package known as an integrated development environment (IDE), a complicated-
sounding name with a simple explanation: it gathers together, or integrates, all the different
tools you need to write, or develop, software into a single user interface, or environment. There
are lots of IDEs available, some of which support many different programming languages
while others, like Thonny, focus on supporting a single language.
Unlike Scratch, which gives you visual building blocks as a basis for your program, Python
is a more traditional programming language where everything is written down. Start your first
program by clicking on the Python shell area at the bottom-left of the Thonny window, then
type the following instruction before pressing the ENTER key:

print("Hello, World!")

When you press ENTER, you’ll see that your program begins to run instantly: Python will
respond, in the same shell area, with the message ‘Hello, World!’ (Figure 5-1), just as you
asked. That’s because the shell is a direct line to the Python interpreter, whose job it is to look
at your instructions and interpret what they mean. This is known as interactive mode, and you
can think of it like a face-to-face conversation with someone: as soon as you finish what you’re
saying, the other person will respond, then wait for whatever you say next.

5 Figure 5-1: Python prints the ‘Hello, World!’ message in the shell area
Free download pdf