+ 1
Pls how do i reassign functions like addition, module and division?
3 Antworten
+ 3
Please try and elaborate a bit more. What are you trying to do? What are some examples? What have you tried?
+ 2
With your given format, you'd have to define all the functions before assigning it to 'operation'.
But what you could do is:
>>> a = 4
>>> b = 7
>>> operator = '*'
>>> print(eval(f'{a}{operator}{b}'))
28
Hope this helped :)
+ 1
def multiply(x, y):
return x * y
a = 4
b = 7
operation = multiply
print(operation(a, b))