使用dict实现swich,通过不同的键映射不同的函数。
swich = {
'hour1':pred.getper1htable,
'hour6':pred.getper6htable,
'hour12':pred.getper12htable,
'hour24':pred.getper24htable
}
data = swich[d]()
本文介绍了一种使用Python字典来实现类似Switch语句的方法,通过将不同的键映射到不同的函数,从而根据输入的键调用相应的函数。这种方法提供了一个灵活且易于扩展的选择结构。
使用dict实现swich,通过不同的键映射不同的函数。
swich = {
'hour1':pred.getper1htable,
'hour6':pred.getper6htable,
'hour12':pred.getper12htable,
'hour24':pred.getper24htable
}
data = swich[d]()
转载于:https://www.cnblogs.com/sunhuahuaa/p/9714528.html
984

被折叠的 条评论
为什么被折叠?