My question is if i have a variable called op which can contain a plus sign, minus sign etc, how can i make use of that op variable to make a calculation? Instead of having multiple if statements how can i do something like this instead
if op in ['+','-', '*', '/']:
return x op y
else:
print("ERROR")
instead of having for example
if op == "+":
return x + y
elif op == "-":
return x - y
....
....
I have tried making op an int but it doesnt work, is there a solution for this or do i have to check if op is any of the possible signs?
EDIT: How can i do the same with a bigger than, smaller than or equal sign?
To check is op is any of these `["=","<",">"]