Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the index of a string in a tuple

Tags:

python

tuples

Tup = ('string1','string2','string3') 

My program returned string2 how do I get it's index within Tup?

like image 454
rectangletangle Avatar asked Oct 26 '10 06:10

rectangletangle


People also ask

How do you find the index number of a tuple in Python?

Python Tuple index() Method Python index() method searches for the given element in a tuple and returns its position. It returns first occurrence of the element in the tuple. Index starts from 0 and end at n-1 where n is length of tuple.


1 Answers

>>> tup.index('string2') 1 

Note that the index() method has only just been added for tuples in versions 2.6 and better.

like image 162
mechanical_meat Avatar answered Sep 27 '22 17:09

mechanical_meat