为啥不对
本帖最后由 代码小白liu 于 2022-3-31 21:14 编辑list1 = ['name', 'age', 'gender']
list2 = ['Tom', 20, 'male']
dict1 = {}
for i in range(len(list1)):
print(list1)
dict1] = dict1]
print(dict1)
这么写为啥不对 因为一开始 dict1 是空列表,你不能访问一个不存在的键
list1 = ['name', 'age', 'gender']
list2 = ['Tom', 20, 'male']
dict1 = {}
for i in range(len(list1)):
print(list1)
dict1] = list2 # 改了这
print(dict1)
页:
[1]