Menu Close

How to find the index of an item in a list with Python?

Sometimes, we want to find the index of an item in a list with Python.

In this article, we’ll look at how to find the index of an item in a list with Python.

How to find the index of an item in a list with Python?

To find the index of an item in a list with Python, we can use the Python list’s index method.

For instance, we write:

print([1, 1].index(1))

Then we print the first index of 1 in the list.

Therefore, 0 is printed.

Conclusion

To find the index of an item in a list with Python, we can use the Python list’s index method.

Posted in Python, Python Answers