Dictionary Data Type
suggest changeA dictionary consists of key-value pairs. It is enclosed by curly braces {} and values can be assigned and accessed using square brackets [].
dic={'name':'red','age':10}
print(dic) #will output all the key-value pairs. {'name': 'red', 'age': 10}
print(dic['name']) #will output only the value with the 'name' key. red
print(dic.values()) #dict_values(['red', 10]), not a list
print(dic.keys()) #dict_keys(['name', 'age']), not a list
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents