方法一

python下标索引 下标 python_Python

摘自Python查找列表中某个元素返回所有下标

 

方法二

name = ['hello', 'world', 'a', 'b', 'c', 1, 2, 3, 'hello', 'world', 'a', 'b', 'c', 1, 2, 3]
first_pos = 0
for i in range(name.count('a')):
    new_list = name[first_pos:]
    next_pos = new_list.index(2) + 1
    print('find ', first_pos + new_list.index('a'))
    first_pos += next_pos

# 运行结果:
#   find  2
#   find  10