Services Work Learn About Contact
0/10
Lesson 8 of 10

Functions

Functions are reusable blocks of code. Define them with the def keyword. You can return values with return and set default parameter values.

PYTHON
def greet(name):
    return f"Hello, {name}!"

def add(a, b=5):
    return a + b

print(greet("Ali"))
print(add(3))       # 8 (uses default b=5)
print(add(3, 4))    # 7
🧠

Quick Quiz

Answer correctly to unlock the next lesson.

Support the mission

This learning platform is 100% free: no ads, no tracking, no paywalls. If it helped you learn something useful, you can support future lessons or donate to Doctors Without Borders, which provides emergency medical care in crisis zones worldwide.

🎉

You completed Python!

You finished all 10 lessons and quizzes. You now know the basics of Python.