I have this piece of code.
def maths(operator):
#different math here..
final = final + number #i want to use the operator arg here
. Later on, i want to call it like maths('+') or maths('-'), so I don't have to use the same piece of code every time.
You are looking for the operator module
def maths(accum):
#...
final = accum(final, number):
x = maths(operator.mul)
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