python学习-使用dict和set

2016-09-26  本文已影响0人  幽谷听泉

dict

score = {'Michael': 95, 'Bob': 75, 'Tracy': 85}
print(score['Michael'])
>>> score['Thomas']
Traceback (most recent call last): 
  File "<stdin>", line 1, in <module>
KeyError: 'Thomas'
>>> 'Thomas' in score
False
>>>score.get('Tom',60)
60
dict1 = {'name':'caideyang','sex':'boy','age':28}
dict2 = dict1.copy()
dict2['job'] = 'teacher'
del dict2['sex']
print dict2
上一篇下一篇

猜你喜欢

热点阅读