【发布时间】:2021-10-15 12:48:22
【问题描述】:
list1 = [[1,2],[3,4]]
list2 = [[2,3],[4,5]]
def function(a,b):
answer =[]
for i in range(len(a)):
for j in range(len(a[0])):
answer[i][j] = a[i][j] + b[i][j]
return answer
print(function(list1,list2))
我是 python 新手。我不知道为什么会出现这个错误。
IndexError: list index out of range
【问题讨论】:
-
for j in range(len(a[0]))的长度为a[0]或嵌套列表
标签: python list indexoutofrangeexception outofrangeexception