Click here to view code image
>>> print ("I love my Raspberry \u03c0!")
I love my Raspberry π!
>>>
Try It Yourself: Create Output with the print Function
This hour you have been reading about creating and formatting output by using the
print function. Now it is your turn to try out this versatile Python tool. Follow these
steps:
- If you have not already done so, power up your Raspberry Pi and log in to the
system. - If you do not have the LXDE GUI started automatically at boot, start it now by typing
startx and pressing Enter. - Open the LXTerminal by double-clicking the LXTerminal icon.
- At the command-line prompt, type python3 and press Enter. You are taken to the
Python interactive shell, where you can type Python statements and see immediate
results. - At the Python interactive shell prompt (>>>), type print ('I learned
about the print function.') and press Enter. - At the prompt, type print ('I learned about single quotes.') and
press Enter. - At the prompt, type print ("Double quotes can also be used.")
and press Enter.
By the Way: Multiple Lines with Triple Double Quotes
In steps 8 through 10, you will not be completing the print function on one
line. Instead, you will be using triple double quotes to allow multiple lines to
be entered and displayed.
- At the prompt, type print ("""I learned about things like... and
press Enter. - Type triple quotes, and press Enter.
- Type and displaying text on multiple lines.""") and press
Enter. Notice that the Python interactive shell did not output the Python print
statement’s argument until you had fully completed it with the closing parenthesis. - At the prompt, type print ('Single quotes protect "double
quotes" in output.') and press Enter. - At the prompt, type print ("Double quotes protect ‘single
quotes’ in output.") and press Enter. - At the prompt, type print ("A backslash protects \"double