my_favourite_fruits = ["apple","orange","pear"]
i = 0
while(True):
print(my_favourite_fruits[i])
i = i+1
此代码当前打印 3 个列表项,然后由于没有要打印的列表项而崩溃。如何使用 while 循环反复打印这些内容?
最佳答案
无需手动计算任何东西。有一个数字并不一定意味着什么,所以无论大小如何处理传入的数据并使用嵌套循环进行迭代。
my_favourite_fruits = ["apple", "orange", "pear"]
while True:
for fruit in my_favourite_fruits:
print(fruit)
关于python - 如何使列表中的项目永远运行 - python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66397354/