python用字典实现switch跳转的简单方法

2018年11月7日23:26:07 发表评论 1,233 views
废话不说 附源码示意

x = 1
y = 2
operator = "/"
result = {
    "+": x + y ,
    "-" : x - y,
    "*" : x * y,
    "/" : x / y}

print(result.get(operator))

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: