''' Demonstrate functions can be pass with function parameter ''' def analyze( x, f ) : # analyze takes in two parameters x (a list of values) and f (a function identifier) ''' Return the result of f( x ) ''' print( 'id(f) = ', id(f) ) result = f( x ) # Since functions are first class (can be used as variables), we can basically # use the function name passed in as a callable function and call it on the list x # ex. back in spooky if called functions_are_first_class.analyze(values, min) # it will find the min(x) / min(values) since values is the argument to x return result # Purpose: functions can be used as variables so that we can use them as callable variables. # We can pass in a function of choice using another function and call that function # so if the function parameter is f then we call the function f # in the function using f( x ) where we pass in x into that function f (whatever that function is) # In the spooky.py tester, we pass in len, max, min, sum as f and call it on the argument values as # list x. # Uncomment this code to see how it works! You should get 'hello' # s = ' hello ' # words = s.strip # words is now a callable variable that stores the function identifier. # We can call s.strip() by just doing: # words() # since words = s.strip # Test functions may include: # Calculations # Accumulator Problems # Functions that produce lists # Functions that produce strings # Functions that produce numbers # Dataset problems # Dictionary Problems # I would recommend going over practice test problems found under Testing on the webppage # in order to get a good grasp of the kinds of function questions for the coding portion # we might ask. Practice makes you get better and faster :)