3. The 'in' Operator - Quick Question


#1



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,:

 my_dict[key]

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.


#2

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)


#3

Thank you for your reply. :slight_smile:


#4

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