美文网首页
python 用字典映射 来代替switch

python 用字典映射 来代替switch

作者: JDL | 来源:发表于2017-12-19 00:15 被阅读0次

def get_sunDay():
print("sunDay====")
return "sunDay"
def get_monDay():
print("monday====")
return "monDay"
def get_tuesDay():
print("tuesDay====")
return "tuesDay"
def get_default():
return "Unknow"

dic={
0:get_sunDay,
1:get_monDay,
2:get_tuesDay
}
displayName=dic.get(1,"get_default")()
print(displayName)

相关文章

网友评论

      本文标题:python 用字典映射 来代替switch

      本文链接:https://www.haomeiwen.com/subject/jbivwxtx.html