字典1-python3

"""
定义和使用字典

Version: 1.0.0
Author: Catherine
Data: 2019-03-11
"""

def main():
    scores = {'Catherine': 95, 'Mike': 78, 'Joey': 82}
    print(scores['Catherine'])
    print(scores['Joey'])
    for elem in scores:
        print("{}--->{}".format(elem, scores[elem]))
    scores['Eric'] = 65
    scores['Tao'] = 71
    scores.update(YiFan=67, Zach=85)
    print(scores)
    if 'Daniel' in scores:
        print(scores['Daniel'])
    print(scores.get('Daniel'))
    print(scores.get('Daniel', 60))
    print(scores.popitem())
    print(scores.popitem())
    print(scores.pop('Catherine', 100))
    print(scores)
    scores.clear()
    print(scores)


if __name__=="__main__":
    main()

猜你喜欢

转载自blog.csdn.net/u011280600/article/details/88427991