标签:dicts nihao dic dict 使用 print 字典
{}使用大括号定义
dicts =
print(dicts['hello'])
dict函数定义
dic = dict([['hello','world']])
print(dic)
dict函数下fromkey函数定义,批量生成字典的键值,同时去除相同的键
dic = dict.fromkeys(['a','a','b','c'],['a'])
print(dic)
字典的增加
方法一
dicts['city'] = '贵州'
print(dicts)
方法二
dicts.update({'city':'贵州'})
print(dicts)
字典删除
pop函数弹出键的值
data = dicts.pop('nihao')
print(dicts,data)
del删除键的值
del dicts['nihao']
print(dicts)
字典修改
dicts['nihao'] = 'shijie'
print(dicts)
字典查询
取所有的键,值
print(list(dicts.keys()),dicts.values())
item取键,值
for key,values in dicts.items():
print(key,values)
循环遍历取键值
for i in dicts:
print(i,dicts[i])
标签:dicts,
nihao,
dic,
dict,
使用,
print,
字典
From: https://www.cnblogs.com/striveforward/p/18233034