[英]Multidimensional Array : index out of range
I'm learning python and wanted to use multidimensional array like we use in c and researched about it and have written the code but stuck at one place and I don't understand why the error is occurring.我正在学习 python 并想使用我们在 c 中使用的多维数组并研究它并编写了代码但卡在一个地方,我不明白为什么会发生错误。
My Code:-我的代码:-
a=[]
i=0
for record in tablerows:
a.append([])
rowcells=record.findAll('td')
for data in rowcells[1:4]:
a[i].append(data.text)
i=i+1
print(a)
Error:错误:
a[i].append(data.text) IndexError: list index out of range. a[i].append(data.text) IndexError:列表索引超出范围。
On second iteration.在第二次迭代中。
Can you please guide me...?你能指导我吗...?
And I'm doing it right or is there a better way of doing it....?我做对了还是有更好的方法来做....?
Shift i = i + 1 out of the second loop, like this.像这样将 i = i + 1 移出第二个循环。
a=[]
i=0
for record in tablerows:
a.append([])
rowcells=record.findAll('td')
for data in rowcells[1:4]:
a[i].append(data.text)
print(a)
i=i+1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.