Home › Python with Chai › Lesson 2
Run a function
Python with Chai, lesson 2 of 20. A short Hinglish video, simple English notes and code you can run, free.
Open the interactive lesson with Run button
The idea
You write a function with def. Writing it doesn't run it; Python just remembers it.
Add () after the name to RUN it. This is called calling the function.
return sends an answer back from the function, which you can store in a variable.
The code
def chai_banao():
print("Paani ubla")
print("Patti daali")
print("Doodh daala")
return "Chai ready!"
cup = chai_banao()
print(cup)
Output:
Paani ubla Patti daali Doodh daala Chai ready!
Try it yourself
- Call
chai_banao()twice. How many times does the output appear? - Write a new function called
coffee_banao().
Remember
Functions: write once, run any time.
← Chai is a Python program · if-else: how much sugar? →
All lessons: Python with Chai