I have a piece of code that is repeating with only a math operator changing, i.e:
x1=a+b
x2=a-b
x3=a*b
x4=a/b
is there a way to write a function that receives the operator and only applies that and thus eliminate the need to write almost the same code many times?
hopefully, something like:
def operator_modularity(op):
return a op b
operator_modularity(+)