''' Demonstrate functions can be pass as arguments ''' def analyze( x, f ) : # This basically takes in a function and what we # wanna put in the function # kinda like function call construction # like len( x ) where x is a list # The purpose again is to show you that functions are first class # and that we can construct function calls in this way as well ''' Return the result of f( x ) ''' result = f( x ) return result if ( __name__ == '__main__' ) : values = [ 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5 ] a1 = analyze( values, print ) print( a1 ) a2 = analyze( values, len ) print( a2 ) a3 = analyze( values, sum ) print( a3 ) a4 = analyze( values, max ) print( a4 ) a5 = analyze( values, min ) print( a5 )