[PYTHON] Dictionary items method

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

Dictionary items method
Manim's method 7
Manim's method 2
Manim's method 18
Manim's method 17
Manim's method 5
Manim's method 3
Manim's method 15
Manim's method 11
Manim's method 16
Manim's method 20
Binary method
Dictionary type 2
Manim's method 10
Dictionary type 1
Manim's method 9
Manim's method 6
Manim's method 21
Manim's method 4
Manim's method 8
Manim's method 14
Python dictionary
Manim's method 22
[Python] dictionary
Manim's method 19
Manim's method 12
Python dictionary
Special method
Special method
Multiple key items using tuples as dictionary keys