字典
- 结构--
字典名={字:解释,…}
- 查字典--
print(字典名[字])
>>> names={'Tom':'Tom is very tall','William':'William is very handsome'}
>>> names
{'Tom': 'Tom is very tall', 'William': 'William is very handsome'}
>>> print(names['Tom'])
Tom is very tall
也可用.get()
查
>>> names
{'Tom': 'Tom is very tall', 'William': 'William is very handsome'}
>>> print(names.get('Tom'))
Tom is very tall
>>> print(names.get('Mary'))
None
.get()自定义返回值
>>> names
{'Tom': 'Tom is very tall', 'William': 'William is very handsome'}
>>> print(names.get('Mary','No here'))
No here
=
、==
、is
辨析
=
--赋值,给数据添加一个地址==
--对数据进行比较is
--对数据地址进行比较
>>> a=[1,2,3,4,5,6]
>>> b=a
>>> c=[1,2,3,4,5,6]
>>> print(a==b)
True
>>> print(a==c)
True
>>> print(a is b)
True
>>> print(a is c)
False
复合数据结构
>>> people={'Tom':{'height':175,'weight':'80kg','color':'blue'},'Mary':{'height':180,'weight':'85kg','color':'black'},'William':{'height':165,'weight':'50kg','color':'green'}}
>>> Tom=people['Tom']
>>> Tom_color=people['Tom']['color']
>>> print(Tom)
{'height': 175, 'weight': '80kg', 'color': 'blue'}
>>> print(Tom_color)
blue
膜拜学习下!
你可是软件资源大佬啊