我是新来的蟒蛇,我真的很喜欢使用字典而不是开关/ case语句的概念,但有一个问题,我想不出如何运行的代码块蟒蛇case语句里面
让我们说我们有一个“Python的情况下,”声明
{
'a': somemethod,
'b': othermethod
}['a']()
这工作得很好,但我无法弄清楚如何在像Java语言编写的运行一些代码块一样,这东西看起来像这样
{
'a': { some commands here }
'b': { other commands here that are executed }
}['a']
也许lambda可以帮忙吗?
非常感谢你
Python没有switch语句,试图让它移植一个on –