Python: lists .remove(item) but not .find(item) or similar?

This question already has an answer here:

  • Finding the index of an item given a list containing it in Python 23 answers

  • Interesting that it's not list.find , but list.index :

    >>> l = ['a', 'b', 'c']
    >>> l.index('c')
    2
    

    To test for membership:

    >>> 'b' in l
    True
    

    Which is equivalent to (and should be used instead of):

    >>> l.__contains__('b')
    True
    
    链接地址: http://www.djcxy.com/p/28122.html

    上一篇: 在字符串中查找单词的位置

    下一篇: Python:列出.remove(item)但不是.find(item)或类似的东西?