A callable object is a first-class citizen, which means it can be used just like any other object, such as an int. Passing a callable object to a function is then done the same way as with any other object:
def my_func():
print("called")
def consume(obj):
if callable(obj):
return obj()
return obj
# pass an int
consume(42)
# pass a callable object
consume(my_func)
IS there a way I can write a function that returns a value and is callable?
def point(a, b):
f():
return a, b
return f
This is callable but doesn't return a or b
def point(a, b):
return a, b
This returns a and b but is not callable
I need a function that can do both