python 用字典映射 来代替switch

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)