可以使用index()方法来索引一个元素在列表中的位置,并使用print()函数打印出来。例如:

my_list = [1, 2, 3, 4, 5]
element = 3
index = my_list.index(element)
print("The element", element, "is located at index", index)

输出结果为:

The element 3 is located at index 2
用Python怎么在一个列表索引一个元素并打印位置

原文地址: https://www.cveoy.top/t/topic/buQY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录