Given a list and we have to find the index of first matched of a list in Python.
给定一个列表,我们必须在Python中找到列表的第一个匹配项的索引。
Example:
例:
Input:
List = [10, 20, 10, 20, 30, 40, 50]
element = 10
Output:
Index of first matched 10 is: 0
Input:
List = [10, 20, 10, 20, 30, 40, 50]
element = 30
Output:
Index of first matched 20 is: 4
list.index()方法 (list.index() Method)
It’s an inbuilt method in Python, it returns the index of first matched element of a list.
这是Python中的内置方法,它返回列表的第一个匹配元素的索引。
Syntax:
句法:
list.index(element)
Her