Lesson 6 · functions
Small helpers
- 1. Story
- 2. Guess
- 3. Your turn
- 4. Catch Sitara’s mistake
KaiI write the same bill sums all day.
SitaraThen make a small helper. Write it once, use it every time.
EllaLike my coffee order. Kai just knows it.
A function is a small helper. You give it inputs, and it returns an answer.
- 1. def makes a helper and gives it a name
- 2. name is the input it receives
- 3. return hands the answer back
cafe.py
Try: Add a line that greets Buddy too.
Read · about 1 minute
The basics, in plain words
A function is a small helper. You give it inputs, and it returns an answer.
def greet(name):
return f"Good morning, {name}!"
print(greet("Ella"))- def makes a helper and gives it a name
- name is the input it receives
- return hands the answer back
- def name(input):
- Makes a function: a small helper you can use again and again.
- return
- Hands the answer back to whoever called the function.
Common slip: Using print instead of return. print only shows the answer; return lets you keep and use it.
Read all twelve Python basics with Sitara →