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

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

提問(wèn)人:ylm發(fā)布時(shí)間:2020-09-29

下面的代碼使用一個(gè)字典來(lái)模擬構(gòu)造一個(gè)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ù)查找其他問(wèn)題的答案?

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