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