After reading lesson 22, you’ll be able to
- Pass functions (as an object) as a parameter to another function
- Return a function (as an object) from another function
- Understand which variables belong to which scope based on certain rules
Before formally learning about functions in lesson 21, you saw and used functions in simple code. Here are some of the functions you’ve been using already:
- len()—For example, len("coffee")
- range()—For example, range(4)
- print()—For example, print("Witty message")
- abs(),sum(),max(),min(),round(),pow()—For example, max(3,7,1)
- str(),int(),float(),bool()—For example, int(4.5)
Consider this
For each of the following function calls, how many parameters does the function take in, and what’s the value of type returned?
- len("How are you doing today?")
- max(len("please"), len("pass"), len("the"), len("salt"))
- str(525600)
- sum((24, 7, 365))
Answer:
- Takes in one parameter, returns 24
- Takes in four parameters, returns 6
- Takes in one parameter, returns "525600"
- Takes in one parameter, returns 396