Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 17, 2020 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/9a033bb80fd1c3e6d60464f5c2b2d57c to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/9a033bb80fd1c3e6d60464f5c2b2d57c to your computer and use it in GitHub Desktop.
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