import ast user_expression = "1 + 1" result = ast.literal_eval(user_expression)