Python中List.index()方法的使用教程
2015-05-20 12:01
711 查看
index()方法返回obj出现在列表中最低位索引。
语法
以下是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()方法的使用教程
- Python中的index()方法使用教程
- Python中的index()方法使用教程
- Python中List.count()方法的使用教程
- Python中List.count()方法的使用教程
- flex list拖拽 calculateDropIndex方法的使用
- 在Python中使用dict和set方法的教程
- 在Python中使用__slots__方法的详细教程
- Python类的定义、继承及类对象使用方法简明教程
- Python2.x版本中cmp()方法的使用教程
- Python中的ceil()方法使用教程
- Python中的ceil()方法使用教程
- Python2.x版本中cmp()方法的使用教程
- Python的randrange()方法使用教程
- Python的randrange()方法使用教程
- Python操作列表之List.insert()方法的使用
- 在Python中操作列表之list.extend()方法的使用
- 在Python中操作列表之List.append()方法的使用
- Python中zfill()方法的使用教程
- 在Python中使用swapCase()方法转换大小写的教程