字典的索引可以使用许多不同类型的数据,不只是整数。字典的索引被称为“键”,键及其关联的值称为“键—值”对,在代码中,字典输入时带花括号{}。5.1.1 keys()、values()和items()方法>>> spam = {'color':'red','age':42} >>> for i in spam.values(): print (i)red 42 >>> list(spam.keys())['color',...【阅读全文】
使用python中的字典来模拟其他语言中的case,switch 语句。使用函数作为字典的value. 看代码很直观。该代码出自The Python Master一书.点击(此处)折叠或打开def labyrinth(position, alive): print('You are in a maze of twisty passages, all alike...【阅读全文】