字典
字典类型是由键值对组成的可迭代对象,每个键值对用,
分割,每个键和值用:
分割
dictionary = {'location':'school','figure':'XiaoMing','time':'1:20am'}
访问字典
字典类型变量[key]
dictionary = {'location':'school','figure':'XiaoMing','time':'1:20am'}
print(dictionary['location'])
OUT:
school
修改字典
字典类型变量[key] = 值
dictionary = {'location':'school','figure':'XiaoMing','time':'1:20am'}
dictionary['location'] = 'home'
print(dictionary['location'])
OUT:
home
遍历字典
dictionary = {'location':'school','figure':'XiaoMing','time':'1:20am'}
dictionary['location'] = 'home'
for key,value in dictionary.items():
print(f'{key}:{value}')
OUT:
location:home
figure:XiaoMing
time:1:20am