← Teacher guide Markdown for Prepare

Functions: cheat sheet

Python functions and events · In any playground, open Reference to copy these.

dot

Draw a filled dot of this size.

dot(20)
Example
dot(30)
hideturtle()
What it draws

def (function)

Name a group of steps, then run it by calling its name.

def shape():
    pass

shape()
Example
def zigzag():
    left(45)
    forward(30)
    right(90)
    forward(30)
    left(45)

zigzag()
zigzag()
zigzag()
What it draws
Defined once, called three times

for each item

Work through a list, one item at a time.

for c in colours:
    pass
Example
pensize(6)
for c in ["red", "blue", "green"]:
    pencolor(c)
    forward(40)
What it draws
One line per colour in the list

print

Show text or a value in the output box.

print("Hello")

in

True if the item is in the list (or the key is in the dictionary, or the letters are in the text).

if item in bag:
    pass