Python 列表/数组方法
值 "cherry" 的位置是:
fruits = ['apple', 'banana', 'cherry'] x = fruits.index("cherry")
运行实例
index() 方法返回指定值首次出现的位置。
list.index(element)
值 32 的位置是:
fruits = [4, 55, 64, 32, 16, 32] x = fruits.index(32)
注释:index() 方法仅返回值的首次出现。