Learning outcomes
By the end of this lecture, you should be able to:- write small utility functions
- return processed values from lists and strings
- compose functions for cleaner code
Example 1: maximum of two numbers
Example 2: count vowels
Example 3: sum of list
Example 4: factorial function
Multiple returns via tuple
Exam hints and traps
- use
returnfor reusable function result - returning
Nonecan be intentional for invalid case - function may return tuple if multiple values are needed
Quick practice
- Write function to count even numbers in a list.
- Write function to reverse a string.
- Write function to return both sum and average of a list.
