文章目录
-
- 01_创建字典.py
- 02_字典常用操作之新增数据.py
- 03_字典常用操作之删除数据.py
- 04_字典常用操作之修改数据.py
- 05_字典常用操作之查找数据.py
- 06_字典的遍历之key.py
- 07_字典的遍历之value.py
- 08_字典的遍历之键值对.py
- 09_字典的遍历之键值对(拆包).py
01_创建字典.py
dict1 = {'name': 'TOM', 'age': 20, 'gender': '男'}
dict2 = {}
dict3 = dict()
print(type(dict3))
02_字典常用操作之新增数据.py
dict1 = {'name': 'TOM', 'age': 20, 'gender': '男'}
dict1['id'] = 110
print(dict1)
dict1['name'] = 'ROSE'
print(dict1)
03_字典常用操作之删除数据.py
dict1 = {'name': 'TOM', 'age': 20, 'gender': '男'}
dict1.clear()
print(dict1)
04_字典常用操作之修改数据.py
dict1 = {'name': 'TOM', 'age': 20, 'gender': '男'}
dict1['id'] = 110
print(dict1)
05_字典常用操作之查找数据.py
dict1 = {'name': 'TOM', 'age': 20, 'gender': '男'}
print(dict1.items())
06_字典的遍历之key.py
dict1 = {'name': 'TOM', 'age': 20, 'gender': '男'}
for key in dict1.keys():
print(key)
07_字典的遍历之value.py
dict1 = {'name': 'TOM', 'age': 20, 'gender': '男'}
for value in dict1.values():
print(value)
08_字典的遍历之键值对.py
dict1 = {'name': 'TOM', 'age': 20, 'gender': '男'}
for item in dict1.items():
print(item)
09_字典的遍历之键值对(拆包).py
dict1 = {'name': 'TOM', 'age': 20, 'gender': '男'}
for key, value in dict1.items():
print(f'{key}={value}')