11

Lesson 11 of 20 ยท Reusable Steps

Reusable Steps โ€” Part 19

Define steps once, then use them again. This is part 19 of 20.

What you'll learn

You will learn how to create reusable code with functions โ€” define once, call many times.

Steps

  1. 1'def say_hi():' creates a function โ€” think of it as teaching the computer a new trick called 'say_hi'.
  2. 2The indented line print('Hi!') is what the trick does. But it doesn't run yet โ€” we've only defined it, not called it.
  3. 3say_hi() on lines 3 and 4 CALLS the function โ€” it tells the computer: 'do that trick now!' It runs twice, so 'Hi!' appears twice.
  4. 4Functions are reusable! Define a function once, then call it as many times as you need. This saves you from repeating code.

Key Terms

Function
A named block of code you can run whenever you want by writing its name and ().
Define
To create a function (with def). You define it once.
Call
To run a function by writing its name and (). Each call runs the function's code.
Python 3
Output
Loading Python... This may take a few seconds.

Your code runs only in your browser. No code is sent to any server. Stay safe and have fun learning!

๐Ÿ–จ๏ธ

Checkout complete lesson on Reusable Steps for 1st Grade

Get the full Reusable Steps track as a printable PDF โ€” all lessons, worksheets, and answer keys.

View in Shop

Your Cart (0)

Your cart is empty

Browse our shop to find activities your kids will love

Reusable Steps โ€” Part 19 โ€” Reusable Steps | 1st Grade Coding | LittleActivity | LittleActivity