Skip to main content
 首页 » 编程设计

python之将 .index() 与具有重复元素的列表一起使用

2025年04月02日17JustinYoung

<分区>

所以我正在检查一个列表并打印所有等于 3 的值

for item in top: 
    if item == 3: 
        print('recommendation found at:') 
        print(top.index(item)) 

问题是这只会不断打印值为 3 的第一个元素。如何打印值为 3 的每个元素的每个位置?