我是新來的蟒蛇,我真的很喜歡使用字典而不是開關/ 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 –