Functions, parameters and return values
Functions, parameters and return values
Define a function with def. Parameters receive values, and return sends a result back to the caller. Default arguments should generally be immutable. Use keyword arguments when they improve clarity.
Try it yourself
Change the example, run it, and explain the result in your own words. Then create one variation of your own.
Key idea
Use the example as a starting point, not something to memorize. Practise, inspect the result and make small improvements.
Code example
def calculate_total(price, quantity=1):
return price * quantity
print(calculate_total(1500, quantity=2))