Python List index()方法

Python 教程 · 2019-02-02 21:56:24

描述

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

语法

index()方法语法:

list.index(obj)

参数

  • obj -- 查找的对象。

返回值

该方法返回查找对象的索引位置,如果没有找到对象则抛出异常。

实例

以下实例展示了 index()函数的使用方法:

#!/usr/bin/python

aList = [123, 'xyz', 'zara', 'abc'];

print "Index for xyz : ", aList.index( 'xyz' ) ;
print "Index for zara : ", aList.index( 'zara' ) ;

以上实例输出结果如下:

Index for xyz :  1
Index for zara :  2

点击查看所有 Python 教程 文章: https://www.codercto.com/courses/l/8.html

查看所有标签

The Black Box Society

The Black Box Society

Frank Pasquale / Harvard University Press / 2015-1-5 / USD 35.00

Every day, corporations are connecting the dots about our personal behavior—silently scrutinizing clues left behind by our work habits and Internet use. The data compiled and portraits created are inc......一起来看看 《The Black Box Society》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具