3. The 'in' Operator - Quick Question


Hello, I have passed this exercise, and I had a question about the code.

my_dict = {
    "Name": "Abby",
    "Age" : 12,
    "Likes Codecademy": True

for key in my_dict:
    print key, my_dict[key]

Without this bit,:


The code only prints the keys; "Name", "Age", and "Likes Codecademy"

So, why does the bit of code (above) print the values? It seems like it would calling the keys of the dictionary, but it adds the values. Earlier in this section, it didn't talk about this so I was curious.


Keys are used to look up values in a dict, that's what is happening after the comma (you should be finding this entirely straight-forward)


Thank you for your reply. :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.