字典dict对应js中的对象Object
keys遍历key、values遍历value、items遍历键值对,for in默认遍历字典的key
info = {'k1': 'v1', 'k2': 'v2'}
for k in info:
print(k)
# k1
# k2
for k in info.keys():
print(k)
# k1
# k2
for v in info.values():
print(v)
# v1
# v2
for k, v in info.items():
print(k, v)
# k1 v1
# k2 v2
del删除字典的属性
info = {'k1': 'v1', 'k2': 'v2'}
del info['k1']
print(info)
# {'k2': 'v2'}