Python - Tuple Methods
Code Life
By Pierre Marsaa
Tuple Methods
Unlike lists, tuples are immutable, which means they have very few methods. In fact, tuples only have two built-in methods:
1.
count(): Counts how many times a value appears in the tuple
2.
index(): Finds the position of a value in the tuple
↗️
Loading editor...
↶
↷
Be careful with index()
If the value doesn't exist in the tuple, index() will raise a ValueError. Always check if the value exists first, or use a try-except block.
Verify