声明:
因本人为AI路上的新手,文章用于辅助个人的整理记忆,理解难免有偏差之处,都是个人拙见,如给其他同僚造成困扰,还请见谅,非常非常非常欢迎私信共同讨论,共同进步
- 函数名:index()
- 作用:获得列表或字符串中某个元素的索引
- 调用方法:
list.index(self, object, start, stop)
str.index(self, sub, start, stop) - 参数:
self:指作用于本身
object/sub: 列表或字符串中的某个元素
start:可指定开始的上限
stop:结束的下限
官方解释:
array.index(x)
Return the smallest i such that i is the index of the first occurrence of x in the array.
少废话,上代码:
lt0 = [1, 2