【Python】Python3 List index()方法

来源:互联网 发布:网络高科技犯罪电视剧 编辑:程序博客网 时间:2024/06/05 16:28

描述
index()函数用于从列表中找出某个值第一个匹配项的索引位置。
语法
index()方法语法:

list.index(obj)

参数

  • obj–查找的对象。

返回值
该方法返回查找对象的索引位置,如果没有找到对象则抛出异常。
实例
以下实例展示了index()函数的使用方法:

list1 = ['Google', 'Runoob', 'Taobao']print("Google的索引值:",list1.index("Google"))print("Taobao的索引值:",list1.index("Taobao"))

以上实例输出结果如下:

Google的索引值: 0Taobao的索引值: 2