Finding the index of a string in a tuple

Question:

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

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

Asked By: rectangletangle

||

Answers:

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

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

Answered By: mechanical_meat
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.