← Back to Python Course Foundations
User Defined Functions (Python)¶
Learning Objectives¶
- Define and call functions with parameters.
- Use default parameter values.
- Return computed results.
Example¶
def area_rectangle(length, width=1):
return length * width
print(area_rectangle(5, 2))
print(area_rectangle(7))
Dry Run¶
area_rectangle(5,2)->10area_rectangle(7)uses default width1->7
Common Mistakes¶
- Forgetting
returnwhen output is needed. - Mismatch in number of arguments.
Practice¶
- Write a function to find max of 3 numbers.
- Return both sum and average from one function.