items.py
num = {'x':100, 'y':200}
print(num.items())
#When processing the dictionary with a for statement, the key is returned
for k in num:
print(k)
#If you want values, use the values method
for v in num.values():
print(v)
#If you want a key / value pair, use the items method
#When processed with a for statement, k,Each v contains a key and a value(Tuple unpacking)
for k, v in num.items():
print(k, ':', v)
Output result:
dict_items([('x', 100), ('y', 200)])
x
y
100
200
x : 100
y : 200
Recommended Posts