User Guide

131
6 – Programming in Python
Python is a widely-used programming language that is available
on most modern operating systems and computers. On the Pi,
Python is a great way to write software and games, and to
control the GPIO pins.
Unlike programming languages such as C++ or Objective-C,
Python is an interpreted language. This means that special
software reads your code files and runs them. You do not have
to compile Python files to executables or .app files before you
can use them.
When programmers write code, they usually do it in a piece of
software called an integrated development environment (IDE).
An IDE is a text editor that is packaged with other tools to make
writing code a little easier. On Raspbian, there are two versions
of Python, and they are incompatible with each other. In this
chapter, you will learn Python 3.
6.1 Your First Python Program
“Hello, World!” is a short program that people often write as
their first program in a new environment or language. It is a test,
and only displays the message “Hello, World!” to the user.
In Python, you can write this program with one line of code, and
it is a good way of introducing you to the IDE and how to run
Python programs.
To start:
1. Click the Raspbian Menu button, point to
Programming, and then click Python 3.
2. Type print("Hello, World!") and then press Enter.
The first thing to note is that the window is titled “Python Shell”.
The Python Shell works like the Linux terminal – it runs
commands that you type here when you press the Enter key.