11
Lesson 11 of 20 · Functions
Functions — Part 19
Parameters and return values. 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'def say_hi():' creates a function — think of it as teaching the computer a new trick called 'say_hi'.
- 2The indented line print('Hi!') is what the trick does. But it doesn't run yet — we've only defined it, not called it.
- 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.
- 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!
Ready?
Functions — Part 19
You will learn how to create reusable code with functions — define once, call many times.
Full screen — no distractions
🖨️View in Shop
Checkout complete lesson on Functions for 7th Grade
Get the full Functions track as a printable PDF — all lessons, worksheets, and answer keys.
