Python Tuple Index () Syntax
Syntax: tuple.index(element, start, end)
Parameters:
- element: The element to be searched.
- start (Optional): The starting index from where the searching is started
- end (Optional): The ending index till where the searching is done
Return type: Integer value denoting the index of the element.
Python Tuple – index() Method
While working with tuples many times we need to access elements at a certain index but for that, we need to know where exactly is that element, and here comes the use of the index() function. In this article, we will learn about the index() function used for tuples in Python.
Example :
The Index() method returns the first occurrence of the given element from the tuple.
Python3
my_tuple = ( 4 , 2 , 5 , 6 , 7 , 5 ) print (my_tuple.index( 5 )) |
Output :
2