I would like to do something like the following:
def add(a, b):
#some code
def subtract(a, b):
#some code
operations = [add, subtract]
operations[0]( 5,3)
operations[1](5,3)
In python, is it possible to assign something like a function pointer?
Did you try it? What you wrote works exactly as written. Functions are first-class objects in Python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With