.index()
Published May 5, 2021Updated Oct 13, 2023
Contribute to Docs
Finds the first occurrence of a particular value within the list.
Syntax
list.index(value, start, end)
The .index()
list method has three parameters:
value
: The string to search for. (Required)start
: The index to start the search. Default is index 0.end
: The position to end the search. Default is end of the string.
Example 1
To find the index the first 'pen'
within the backpack
list:
Example 2
To find the index the first 'pen'
within the backpack
list within index 3 to index 6:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly90 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours