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