Tup = ('string1','string2','string3')
My program returned string2 how do I get it's index within Tup?
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.
>>> tup.index('string2') 1
Note that the index()
method has only just been added for tuples in versions 2.6 and better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With