Python 查找列表项的索引 list类的index()方法返回给定项的第一次出现的索引。 语法 list.index(obj) PythonCopy 返回值 index() 方法返回一个整数,代表对象第一次出现的索引。 示例 看下面的示例 − lst = [25, 12, 10, -21, 10, 100] print ("lst:", lst) x = lst.index(10) print ("First index of 10:", x) PythonCopy 它将产生以下 输出 − lst: [25, 12, 10, -21, 10, 100] First index of 10: 2 PythonCopy