Python工作笔记-dictionary的遍历以及enumerate使用以及Py3中has_key的替代
生活随笔
收集整理的這篇文章主要介紹了
Python工作笔记-dictionary的遍历以及enumerate使用以及Py3中has_key的替代
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
程序運行截圖如下:
源碼如下:
if __name__ == '__main__':diction={'1' : 'test1', '2' : 'test2', '3' : 'test3', '4' : 'testA'}hasKey={'2' : 'NiMei'}print("\nThe diction keys are ", end = " ")print(diction.keys())print("The hasKey keys are ", end = " ")print(hasKey.keys(), end="\n\n")i=0for element in diction:print( "i:" + str(i) + "\t" + "element:" + element + "\t" + "diction[element]:" +diction[element])i += 1passprint("\n\n")for j, element in enumerate(diction):print("j:" + str(j) + "\t" + "element:" +element + "\t" + "diction[j]" + diction[str(j+1)])passif '2' in hasKey:print("hasKey.has_key('2') is true !")else:print("hasKey.has_key('2') is false !")if '1' in hasKey:print("hasKey.has_key('1') is true !")else:print("hasKey.has_key('1') is false !")pass?
總結
以上是生活随笔為你收集整理的Python工作笔记-dictionary的遍历以及enumerate使用以及Py3中has_key的替代的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt工作笔记-以配置文件的方式动态获取M
- 下一篇: 编码风格工作笔记-初步模仿大佬编码风格