标签:code ict items item 报错 支持 pytho body size
# 有数据 dict1 = {‘name‘: ‘小明‘, ‘sex‘: ‘男‘} # 空字典 dict2 = {} dict3 =dict() # 函数定义
增/改 |
(有则改之,无则新增) |
删 |
|
查 |
如果当前查找的key存在,则返回对应的值,否则报错
如果当前查找的key值不存在则返回第二个参数,如果省略第二个参数,则返回None
dict1={‘name‘:‘Tom‘, ‘age‘:20,‘sex‘:‘男‘}
print(dict1.keys()) # print(dict1.values())
dict_keys([‘name‘, ‘age‘, ‘gender‘]) # dict_values([‘Tom‘, 20, ‘男‘])
print(dict1.items()) # dict_items([(‘name‘, ‘Tom‘), (‘age‘, 20), (‘gender‘, ‘男‘)])
|
遍历 |
for item in dict1.items(): print(item) for key,value in dict1.items(): print(f‘{key}={value}‘) |
标签:code ict items item 报错 支持 pytho body size
原文地址:https://www.cnblogs.com/LynHome/p/12386267.html