turned-on flat screen TV
Photo by Alexandru Acea on Unsplash

As Python is one of the most popular languages right now, many developers from other languages may also start using it whether that is just on a side project, or a simple script that can help them automate some tasks.

They may have been able to see how to actually find the index in an array, for example in Java, where you write the name of the array and also the index in the brackets. This is also available in Python.

However, something that may be in Python that may not be in other programming languages is the fact that you can declare tuples. At least, this does not come as a built-in type that you can use without implementing any generic type that you can then call or inherit in subclasses.

If you happen to use tuples and are not sure how to find the index of an element in it, then you can do it quite easily using the method index.

Let us take an example and see this in practice.

If you printed the result, you may have been misled thinking that you would get a 3 printed instead of a 2, since you were a bit confused by the presence of a “3” in the actual value of that particular element of the tuple.

This may be something quite simple, but it may be worth knowing that it exists in case you need it.