index()

index() 用于返回序列中指定元素的索引值,字符串 、元组 、列表都属于序列

In [1]: str = "hello world"

In [2]: str.index('e')    # 返回元素'e'在序列中的索引值
Out[2]: 1

In [3]: str.index('l')    # 如果有相同元素,则默认返回第一个出现的元素的索引值
Out[3]: 2

 

 

 

 

    

posted @ 2018-12-27 18:20  孔雀东南飞  阅读(369)  评论(0编辑  收藏  举报