pythonの反復

2464 ワード

辞書の反復:
#    
dict={'a':1,'b':2,'c':3}

#key value   
for key,value in dict.items():
    print(key,':',value)

#key   
for key in dict:
    print(key)

#value   
for value in dict.values():
    print(value)
    
#          
from collections import Iterable
isinstance(dict,Iterable)

リストには、下付きの反復が表示されます.
#    list
l=[]
for i in range(10):
    l.append(i)

#       
for i ,value in enumerate(l):
    print(i,value)