This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
age = {'Amy': 18, 'Ben': 24} | |
age['Ben'] = 60 | |
print(age) | |
# 打印出{'Amy': 18, 'Ben': 60} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
age = {'Amy': 18, 'Ben': 24} | |
del age | |
print(age) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
age = {'Amy': 18, 'Ben': 24} | |
age.clear() | |
print(age) | |
# 打印出 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
age = {'Amy': 18, 'Ben': 24} | |
del age['Amy'] | |
print(age) | |
# 打印出 {'Ben': 24} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
age = {'Amy': 18, 'Ben': 24} | |
age['Coco'] = 20 | |
print(age) | |
# 打印出{'Amy': 18, 'Ben': 24, 'Coco': 20} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
person = {'name': 'Amy', 'name': 'Ben'} | |
print(person['age']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
person = {'name': 'Amy', 'name': 'Ben'} | |
name = person['name'] | |
print(name) | |
# 打印出Ben |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
person = {'name': 'Amy', 'age': 18} | |
name = person['name'] | |
print(name) | |
# 打印出Amy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 方式二: | |
person = dict(name='Amy', age=18) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 方式一 | |
person = {'name': 'Amy', 'age': 18} |