How does Python recognize that it needs only to read the key from the dictionary when using a ‘for’ loop to python iterate over dictionary?
In the following code:
d = {'x': 1, 'y': 2, 'z': 3}
for key in d:
print(key, 'corresponds to', d[key])
Is key
a special keyword, or is it simply a variable? How does Python understand that it should iterate over the keys of the dictionary in this case?