Python 列表 index() 方法

实例

值 "cherry" 的位置是:

fruits = ['apple', 'banana', 'cherry']

x = fruits.index("cherry")

运行实例

定义和用法

index() 方法返回指定值首次出现的位置。

语法

list.index(element)

参数值

参数 描述
element 必需。任何类型(字符串、数字、列表等)。要搜索的值。

更多实例

实例

值 32 的位置是:

fruits = [4, 55, 64, 32, 16, 32]

x = fruits.index(32)

运行实例

注释:index() 方法仅返回值的首次出现。

Python 教程

文件处理

Python NumPy

机器学习

Python MySQL

Python MongoDB

Python 参考手册

模块参考手册

Python How To

Python 实例

目录