×

python · level 1 · unit 7 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A is a recipe card with a name on top.

A function is a set of instructions wrapped up under one name. You write the recipe once, then cook it as often as you like, without copying a single line.

To a function, type def, a name, empty brackets and a colon. The indented lines underneath are the recipe. Defining it does not run it. It only writes the card.

To it, write its name with brackets, like cheer(). Every line in the recipe then runs, top to bottom. Call it twice and it runs twice.

def cheer():
    print("Go team!")
    print("You can do it!")
cheer()
cheer()

def is short for define, and if you change the recipe, every call uses the new version.