小编Rhy*_*rry的帖子

在列表中打印备用元素(引发IndexError:列表索引超出范围)

如何打印列表中的所有其他项目而不会给我这个错误?

我很困惑,我已经以百万种不同的方式尝试了这一百万次,但同样的答案.我的代码现在:

item = 0
fruit = ['Strawberry','apple','pear','orange','banana','cucumber','tomato','Kiwi']
for count in fruit:
    print(fruit[item])
    item = item + 2
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

python for-loop list slice python-3.x

-2
推荐指数
1
解决办法
4375
查看次数

标签 统计

for-loop ×1

list ×1

python ×1

python-3.x ×1

slice ×1