# function_pointers.py # This is the Python equivalent to the function_pointers.c # Python can pass around pointers to functions def print_int(i): print(i) def print_fancy( i ): print( "The int is", i ); # Pretend this does a whole lot more than call do_it. def process_int( do_it, the_int_to_process ): do_it( the_int_to_process ) print( "I have done it" ) def main(): # The type of func is a pointer to a function and its value is # the function print_int (note this doesn't execute print_it) func = print_int print( func ) # call a function pointer func(10); # process_int can call any function expecting a single int! process_int( print_int, 20 ) process_int( print_fancy, 20 ) if __name__ == '__main__': main()