Published Oct 14, 2022
Contribute to Docs
.index() method returns the index of the first occurrence of a specific value in a tuple. Otherwise, an exception is raised.
value is required in order for the
.index() to search the
The following is an example of the
my_tuple = ("I'm", "over", "here")print(my_tuple.index("here"))# Output: 2
The following example throws a
ValueError because the specified value does not exist in the tuple (values passed to
.index() are case-sensitive):
Looking to contribute?
- 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
Computer ScienceLooking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Includes 6 Courses
With Professional Certification