20
Lesson 20 of 20 ยท Functions
Functions โ Part 9
Parameters, return, reuse. This is part 9 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!
๐จ๏ธView in Shop
Checkout complete lesson on Functions for 8th Grade
Get the full Functions track as a printable PDF โ all lessons, worksheets, and answer keys.
