字典的增删改查
增
dictory = {'猫':'cat','狗':'dog','狼':'holf'}
print(dictory)
{'猫': 'cat', '狗': 'dog', '狼': 'holf'}
dictory['书'] = 'book'
print(dictory)
{'猫': 'cat', '狗': 'dog', '狼': 'holf', '书': 'book'}
dictory.update({'猪':'bee','鸟':'bird'})
print(dictory)
{'猫': 'cat', '狗': 'dog', '狼': 'holf', '书': 'book', '猪': 'bee', '鸟': 'bird'}
删
del dictory['猫']
print(dictory)
{'狗': 'dog', '狼': 'holf', '书': 'book', '猪': 'bee', '鸟': 'bird'}
改
dictory['书'] = 'booook'
print(dictory)
{'狗': 'dog', '狼': 'holf', '书': 'booook', '猪': 'bee', '鸟': 'bird'}
查
print(dictory.keys())
dict_keys(['狗', '狼', '书', '猪', '鸟'])
print(dictory.values())
dict_values(['dog', 'holf', 'booook', 'bee', 'bird'])
print(dictory.items())
dict_items([('狗', 'dog'), ('狼', 'holf'), ('书', 'booook'), ('猪', 'bee'), ('鸟', 'bird')])
for i in dictory:
print(i)
狗
狼
书
猪
鸟
print(dictory.get('bee'))
None