Traversal Dictionary

  • Traversing the dictionary key value

    a = {'a': '1', 'b': '2', 'c': '3'}
    for i in a.keys():
        print(i)
    ## y与下面代码等价
    for i in a:
        print(i)
  • Traversing the dictionary value value

    a = {'a': '1', 'b': '2', 'c': '3'}
    for value in a.values():
        print(value)
  • Traversing the dictionary entry

    for kv in a.items():
           print(kv)
            # kv是元祖
  • Traversing the dictionary key

    for key,value in a.items():
           print(key+':'+value)
    
    

Guess you like

Origin www.cnblogs.com/rise0111/p/11447393.html