小白教程
所有教程
关于
Search
172.69.59.163
172.69.59.163
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 att list index”的源代码
本页内容
上一节:
Python3_att_list_extend
下一节:
Python3_att_list_insert
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:list.index(obj)}}[[Category:python3 list|8]] = Python3 List index()方法 = [[python3 list|Python3 列表]] == 描述 == index() 函数用于从列表中找出某个值第一个匹配项的索引位置。 == 语法 == index()方法语法: <sample title="" desc="" lang="python" hererun="1"> list.index(x[, start[, end]]) </sample> == 参数 == * x-- 查找的对象。 * start-- 可选,查找的起始位置。 * end-- 可选,查找的结束位置。 == 返回值 == 该方法返回查找对象的索引位置,如果没有找到对象则抛出异常。 以下实例展示了 index()函数的使用方法: == 实例 1 == <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 list1 = ['Google', 'xiaoBai', 'Taobao'] print ('xiaoBai 索引值为', list1.index('xiaoBai')) print ('Taobao 索引值为', list1.index('Taobao')) </sample> 以上实例输出结果如下: <sample title="" desc="" lang="python" hererun="1"> xiaoBai 索引值为 1 Taobao 索引值为 2 </sample> == 实例 2 == <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 list1 = ['Google', 'xiaoBai', 'Taobao', 'Facebook', 'QQ'] # 从指定位置开始搜索 print ('xiaoBai 索引值为', list1.index('xiaoBai',1)) </sample> 以上实例输出结果如下: <sample title="" desc="" lang="python" hererun="1"> xiaoBai 索引值为 1 </sample> [[python3 list|Python3 列表]]
返回至“
Python3 att list index
”。
上一节:
Python3_att_list_extend
下一节:
Python3_att_list_insert