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

查看所有标签

Paradigms of Artificial Intelligence Programming

Paradigms of Artificial Intelligence Programming

Peter Norvig / Morgan Kaufmann / 1991-10-01 / USD 77.95

Paradigms of AI Programming is the first text to teach advanced Common Lisp techniques in the context of building major AI systems. By reconstructing authentic, complex AI programs using state-of-the-......一起来看看 《Paradigms of Artificial Intelligence Programming》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具