def jia(x,y):
    return x+y
def jian(x,y):
    return x-y
def cheng(x,y):
    return x*y
def chu(x,y):
    return x/y

#建一个字典,使得对应的运算符取到对应的运算方法:
operator = {"+":jia,"-":jian,"*":cheng,"/":chu}


def f(x,o,y):
    #单独的看operator.get(o),其实就等于,jia,jian,cheng,chu 中的一种
    print(operator.get(o)(x,y))


f(4,"+",9)

#switch 实现 加减乘除的方法!

 

相关文章:

  • 2023-03-27
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-06-16
  • 2021-10-20
猜你喜欢
  • 2022-01-22
  • 2021-06-22
  • 2021-09-22
  • 2021-05-28
  • 2022-12-23
  • 2021-11-13
  • 2022-01-21
相关资源
相似解决方案