首页 > 代码库 > Learn Python 009: Dictionary

Learn Python 009: Dictionary

# create a dictionary
students = {"Alice": 24, "Bob": 26, "Clark": 23, "Dan": 28, "Emma": 31}
# add entry to a dictionary
students[‘Fred‘] = 27
# alter an entry
students[‘Alice‘] = 25
# delete entry
del students[‘Fred‘]

students2 = {
        "Alice": [‘ID01‘, 24, ‘A-‘],
        "Bob": [‘ID02‘, 26, ‘B+‘],
        "Clark": [‘ID03‘, 23, ‘B‘],
        "Dan": {‘id‘: ‘ID04‘, ‘age‘: 28, ‘grade‘: ‘A‘},
        }

 

Learn Python 009: Dictionary