Python的列表索引范围
ls是一个非空列表 ,那么它的元素的索引范围是。
0 ~ len(ls)-1
size = len(ls)
indexmax = size - 1
正向索引:
0,1,2,3,...., indexmax
反向索引:
-size, -size+1, -size+2, ... , -2, -1
ls = [1,2,3,4]//非空列表demo
length = len(ls)//获取列表长度
for i in range(length)://for循环
print(ls[i])
直接利用len()函数就能解决