Data Sheet

ADVENTURES IN RASPBERRY PIBC8
Bonus chapter.indd 8 Trim size: 7.375 in × 9.1875 in October 24, 2017 7:20 PM
Python Command Quick Reference Table
Command Description
#
The # symbol is used at the beginning of a code line
to indicate the line is a comment, not part of the
program’s instructions to the computer.
\n
Returns a new line in a string.
break
Breaks out of a for or while loop.
def
Allows you to dene a function of your creation.
elif
Short for ‘else if’, the elif syntax allows you to create
multiple 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 hap-
pen.
if...else
Sets a condition which, if true, makes one set of things
happen, or if false makes a different set of things hap-
pen.
import
Imports modules and libraries to add more functionality
to your code.
input()
A function that asks for user input and converts it into a
string.
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
number 3in the inventory list.
random
A Python module that returns a random value.
return
The return keyword is used when a function is ready to
return a value.
time
Python module that provides various time-related
functions, such as
sleep.
while
A while loop continually repeats if a given condition is
true.
Chapter 5