Find what index an element is in a list

This question already has an answer here:

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

  • Of course there is. Try

    >>> ['cow', 'dog', 'cat'].index('cow')
    0
    

    May i suggest, don't use list as a variable name, as it is already used for constructing a list object.

    链接地址: http://www.djcxy.com/p/28120.html

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

    下一篇: 查找元素在列表中的索引