1. 字典的定义和修改和删除
alien_0 = {}
print(alien_0)
alien_0['x_position'] = 0
alien_0['y_position'] = 25
print(alien_0)
alien_0 = {'color': 'green', 'points': 5}
del alien_0['points']
2 字典的遍历
user_0 = {'username': 'efermi', 'first': 'enrico', 'last': 'fermi'}
for k, v in user_0.items():
user_0 = {'username': 'efermi', 'first': 'enrico', 'last': 'fermi'}
for k in user_0.keys():
pass
for k in sorted(user_0.keys()):
pass
user_0 = {'username': 'efermi', 'first': 'enrico', 'last': 'fermi'}
for v in user_0.values():
pass
for v in set(user_0.values()): #添加进set,可以去除重复
pass
网友评论