-
-
Save IndhumathyChelliah/9a033bb80fd1c3e6d60464f5c2b2d57c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t=('red','blue','green','red','yellow') | |
#Returns the index of first occurence of 'red' | |
print (t.index('red')) #Output: 0 | |
print (t.index('blue'))#Output:1 | |
#If element is not in tuple means raise an ValueError. | |
#print (t.index('yellow'))#Output:ValueError: tuple.index(x): x not in tuple | |
#search the element 'blue' from second index | |
#print (t.index('blue',2)) | |
#Output:ValueError: tuple.index(x): x not in tuple | |
#will search the element 'yellow' from index 1 till index 3 | |
print (t.index('yellow',1,3)) | |
#Output:ValueError: tuple.index(x): x not in tuple |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment