All is well 3 idiots

AC小小常

【Python基础知识】(10)List的遍历

# 遍历列表
persons = ["张三","李四","王五","赵六","钱七","孙八"] # for循环遍历列表 # for 迭代变量 in 可迭代对象
i = 0
# 获取列表长度:len(str)
length = len(persons)
for p in persons:
if p == "李四":
#获取倒序下标 ri = length * -1 + i
print(p , i , ri)
i
+= 1
# 输出:李四 1 -5
# while循环遍历列表
i = 0
while i < len(persons):
p
= persons[i]
if p == "李四":
# 获取倒序下标 ri = length * -1 + i
print(p, i, ri)
i
+= 1
# 输出:李四 1 -5

 

posted on 2020-04-01 16:32  AC小小常  阅读(323)  评论(0)    收藏  举报

导航