Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 281 Bytes

File metadata and controls

28 lines (23 loc) · 281 Bytes

dictionary in python

add and get

dic = {}
dic[1] = 'b'
print(dic[1])
print(1 in dic)

结果

b
True

iterate

>>> a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
>>> for key in a_dict:
...     print(key)
...
color
fruit
pet