If type(is_even) really says 'function', what stops you from giving it a second name or passing it into another function like any other value?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
A function is an object, so it has a type just like a number or a string does. The function double is given above. Ask Python for its type and assign the answer to type_of_double.
Hint: the built-in type() returns an object's type.
def double(n):
return n * 2type(is_even) is function
Record that a function has type function, an object like an int or a float, and list the three moves it allows: assignment to a new name, passing as an argument, returning from a function.
A second name bound to one function object
Draw the memory picture for my_func = is_even written without parentheses, two names on one object, and record a = my_func(3) giving False and b = is_even(4) giving True.
Tracing calc(add, 2, 3) from the outside in
Map op to add, x to 2 and y to 3, substitute into return op(x, y) to reach add(2, 3), and record the 5 that add hands to calc and calc to the main program.
The div variant leaving res as None
Trace calc(div, 2, 0) two scopes deep, recording the printed Denom was 0., the None that div returns to calc, and the None that calc passes on to res.