I want to pass a function to a function in Python. I know I can do this simply by putting the function name as a parameter, eg:
blah(5, function)
However, I want to pass the int() function and the float() function to this function. If I just put the function name in then it assumes I am referring to the int and float types not the functions for converting strings to ints and floats.
Is there a way to pass the function rather than the type?
Just passing
intandfloatis fine. You are right that this will actually pass type objects instead of functions, but that’s not important. The important thing is that the passed object is callable, and calling the type objects will do what you expect.