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

(singke) #1

basic features and take a look around the environment:



  1. If you have not already done so, power up your Raspberry Pi and log in to the
    system.

  2. If you do not have the LXDE GUI started automatically at boot, start it now by typing
    startx and pressing Enter.

  3. Open IDLE for Python v3 by double-clicking the IDLE 3 icon or clicking the LXDE
    Programs Menu icon; hovering over the Programming menu option; and clicking the
    IDLE 3 menu option. You are now in the main IDLE interactive mode window.


By the Way: IDLE 3 Not IDLE
You may notice an IDLE icon and an IDLE menu option alongside the IDLE 3
options. These selections offer the IDLE shell for Python v2. Be sure to select
IDLE 3 to stay on course with this hour.


  1. In the IDLE 3 window, at the >>> prompt, type print and then pause and look at
    the screen. You should notice that the print command has been colored violet. This is
    because the print statement is considered a built-in function in Python. (You will
    be learning more about the various built-in functions in the coming hours.) The color
    is provided to help you recognize the syntax of your Python statement and assist in the
    logic of your scripts. Look back to Table 3.1 for a reminder of the various IDLE
    color codes.

  2. Press the space bar and type ("This is my first Python" and then pause
    again and look at the screen. You should notice that the text This is my first
    Python is colored green because Python considers it a string literal. (You will be
    learning more about string literals, too, in the coming hours. For now, just notice the
    color.)

  3. Instead of correctly finishing your Python statement, just press the Enter key. (You
    are deliberately trying to generate a syntax error to see how IDLE handles syntactical
    problems.) You should get the message Syntax Error: EOL error while
    scanning string literal. This is because you did not correctly close the
    print function. (Well, actually, you were just following directions.)

  4. In the IDLE 3 window, type print ( and then pause. You should see a screen tip
    appear in your window, similar to the one shown in Figure 3.6. IDLE attempts to
    help you by giving guidance via screen tips.

Free download pdf