1 个回答|331 次阅读
使用len()函数确定列表的长度,然后从 0 开始,通过引用列表项的索引在列表项中循环。注意要在每次迭代后将索引增加 1。
打印所有项目,使用while循环遍历所有索引号
fruitlist = ["apple", "banana", "cherry"]
i = 0
while i < len(fruitlist):
print(fruitlist[i])
i = i + 1
执行结果:
apple
banana
cherry
请先 登录 后评论