def get_operator_fn(op):
    return {'+': operator.add, '-': operator.sub, '*': operator.mul, '/':
        operator.div, '%': operator.mod, '^': operator.xor}[op]

def eval_binary_expr(op1, operator, op2):
    op1, op2 = int(op1), int(op2)
return get_operator_fn(operator)(op1, op2)
print(eval_binary_expr(*'1 + 3'.split()))
print(eval_binary_expr(*'1 * 3'.split()))
print(eval_binary_expr(*'1 % 3'.split()))
print(eval_binary_expr(*'1 ^ 3'.split()))
Python:: Turn string into operator