Python List index()方法

栏目: 编程语言 · Python · 编程教程 · python 教程 · 发布时间: 9年前

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

描述

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 List index()方法》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web ReDesign 2.0

Web ReDesign 2.0

Kelly Goto、Emily Cotler / Peachpit Press / 2004-12-10 / USD 45.00

If anything, this volume's premise--that the business of Web design is one of constant change-has only proven truer over time. So much so, in fact, that the 12-month design cycles cited in the last ed......一起来看看 《Web ReDesign 2.0》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

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

在线图片转Base64编码工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换