zoukankan      html  css  js  c++  java
  • Python字典遍历

     1 def dict_test():
     2     #初始化字典
     3     dict= {"a1":"1","a2":"2","a3":"3"}
     4 
     5     #遍历Key
     6     print("遍历Key
    ")
     7     for key in dict:
     8         print(key+':'+dict[key])
     9     #遍历Key
    10     print("遍历Key
    ")
    11     for key in dict.keys():
    12         print(key + ':' + dict[key])
    13     #遍历Value
    14     print("遍历Value
    ")
    15     for value in dict.values():
    16         print(value)
    17     #遍历字典项
    18     print("遍历字典项
    ")
    19     for kv in dict.items():
    20         print(kv)
    21     #遍历键值对
    22     print("遍历键值对
    ")
    23     for k,v in dict.items():
    24         print("k:",k,"v:",v)
    25 if __name__ == '__main__':
    26     dict_test()

  • 相关阅读:
    3.10 Go Map哈希表
    3.9 Go Slice切片
    3.8 Go Array数组
    3.7 Go指针
    3.6 Go String型
    3.5 Go布尔型
    3.4 Go字符型
    3.3 Go浮点型
    3.2 Go整数类型
    3.1Go变量
  • 原文地址:https://www.cnblogs.com/rainbow-1/p/15449412.html
Copyright © 2011-2022 走看看