Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
development of Python programs. As with the interactive shell, each Python statement is
interpreted as it is entered. However, you can also develop entire Python programs, called
scripts.
Text editors—A text editor is a program that allows you to create and modify regular text files.
A text editor does not format the text for display on a printed page, like a word processor does.
Python statements are not interpreted as they are entered in a text editor. This tool only helps
you to quickly create a Python script.

By the Way: Running Python Scripts
After a Python script file is created, it is run either using a command at the command
line or via the development environment shell. And even though a script has multiple
Python statements in it, each statement is still interpreted one at a time, as it is
encountered in the file.

Now that you have had a short introduction to the various Python tools, you can start exploring them in
more depth. Learning to use these tools will help you as you learn Python programming.


Learning About the Python Interactive Shell


The Python interactive shell is primarily used to try out Python statements and check syntax. To enter
the interactive Python shell, type in the command python3 at the command line and press Enter.


By the Way: The Python v2 Interactive Shell
If you want to try out old Python v2 statements, you can still access the Python v2
interactive shell on Raspbian. Just type in the command python2 and press Enter.

Figure 3.2 shows the interactive shell. Notice that the top bar of the window displays the Python
interpreter’s version number. After a little helpful information, the prompt is shown as three greater-
than signs, >>>.


FIGURE 3.2 The Python interactive shell.

At this point, you can simply enter a Python statement and press Enter to have the shell interpret it.
The Python interpreter checks the statement’s syntax. If the syntax is correct, the statement is
translated into binary code and executed.


By the Way: GUI or Command Line?
The Python interactive shell examples in this hour are shown using the LXTerminal in
Free download pdf