汪汪一只猫
if __name__ == '__main__':print(eval("12 * 23 +34"))print(eval("12 - 23 / 34"))print(eval("12 ** 23"))可以用eval()函数,里面直接写string类型的表达式即可,放到函数里就是拼接字符串附一个其他方法的小例子# 函数的默认参数def arithmetic(x=1, y=1, operator="+"):result = {"+": x + y,"-": x - y,"*": x * y,"/": x / y}return result.get(operator) # 返回计算结果print(arithmetic(1, 2))print(arithmetic(1, 2, "-"))print(arithmetic(y=3, operator="-"))print(arithmetic(x=4, operator="-"))print(arithmetic(y=3, x=4, operator="-"))