Hardware Reference
In-Depth Information
Continuing Your Python
Adventure
If you want to learn more about programming in Python on your Raspberry Pi, you can
ind a wide assortment of resources. Here are a few to try:
For more detailed information on Python basics, I recommend Python Basics by
Chris Rofey (Cambridge University Press, 2012).
he oicial Python documentation is available at http://docs.python.
org/3.
Visit http://inventwithpython.com for links to online PDFs that teach
you how to invent your own computer game with Python.
Python Command Quick Reference Table
Command
Description
#
The # symbol is used at the beginning of a code line to indi-
cate the line is a comment, not part of the program's instruc-
tions to the computer.
Returns a new line in a string.
\n
Breaks out of a for or while loop.
break
Allows you to deine a function of your creation.
def
elif
Short for 'else if', the elif syntax allows you to create multi-
ple conditions that make something happen when they return
a value of true .
for
for loops are traditionally used when you have a piece of
code which that you want to repeat x number of times.
if
Sets a condition which, if true, makes something happen.
Sets a condition which, if true, makes one set of things hap-
pen, or if false makes a different set of things happen.
if…else
Imports modules and libraries to add more functionality to
your code.
import
A function that asks for user input and converts it into a
string.
input()
inventory = [“Torch”,
“Pencil”, “Rubber
Band”, “Catapult”]
An example of a list in python. Lists can contain values or
strings that are separated by commas and encased in square
brackets.
name = value
An example of a variable.
print()
A function that prints anything inside the brackets.
print(inventory[3])
An example of using the print() function to print item num-
ber 3 in the inventory list.
A Python module that returns a random value.
random
Search WWH ::




Custom Search