Python - use an operator at runtime
Is it possible to insert an operation (e.g *, +) between two variables at runtime? My solution without doing this is multiple if, elif statements, but I don't think that's the most efficient way to do it.
EDIT: What I meant is I get two integers, and I want to apply an operation on one of them with the other, e.g x * y, but I want to change * to another operator (maybe they're called functions? Not sure) e.g -, +,^ based on input.
Does that make sense? Basically think of it as a calculator.
I'm not sure if this is what you're looking for but the operator module has a lot of operations, e.g. add and mul (multiply):
import operator var_1 = 2 var_2 = 3 print(operator.add(var_1, var_2)) print(operator.mul(var_1, var_2))