CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day07/dict1.py
Views: 729
1
"""
2
定义和使用字典
3
4
Version: 0.1
5
Author: 骆昊
6
Date: 2018-03-06
7
"""
8
9
10
def main():
11
scores = {'骆昊': 95, '白元芳': 78, '狄仁杰': 82}
12
print(scores['骆昊'])
13
print(scores['狄仁杰'])
14
for elem in scores:
15
print('%s\t--->\t%d' % (elem, scores[elem]))
16
scores['白元芳'] = 65
17
scores['诸葛王朗'] = 71
18
scores.update(冷面=67, 方启鹤=85)
19
print(scores)
20
if '武则天' in scores:
21
print(scores['武则天'])
22
print(scores.get('武则天'))
23
print(scores.get('武则天', 60))
24
print(scores.popitem())
25
print(scores.popitem())
26
print(scores.pop('骆昊', 100))
27
scores.clear()
28
print(scores)
29
30
31
if __name__ == '__main__':
32
main()
33
34