位置:首頁 > 軟件操作教程 > 編程開發(fā) > Python > 問題詳情

python應(yīng)用操作——在Python中實現(xiàn)一個真正的switch-case語句

提問人:ylm發(fā)布時間:2020-09-29

下面的代碼使用一個字典來模擬構(gòu)造一個switch-case。

In [104]: def xswitch(x):

     ...:     return xswitch._system_dict.get(x, None)

     ...:

 

In [105]: xswitch._system_dict = {'files': 10, 'folders': 5, 'devices': 2}

 

In [106]: print(xswitch('default'))None

 

In [107]: print(xswitch('devices'))2

 

繼續(xù)查找其他問題的答案?

相關(guān)視頻回答
回復(fù)(0)
返回頂部