Table of Contents » Reference Materials : Tuple Methods
Tuple Methods
Python tuples are immutable sequences, and they have a limited set of methods reflecting their simplicity and immutability. The primary methods include count(value), which returns the number of times a specified value appears in the tuple, and index(value, [start, [end]]), which finds the first occurrence of a specified value and can optionally be restricted to a subsequence of the tuple. Due to the immutable nature of tuples, methods that modify the data, like those found in lists, are absent. This limited set of methods ensures that tuples remain a fast, lightweight, and reliable data structure for storing ordered, unchangeable sequences of elements, making them ideal for storing data that should not be modified, like coordinates or fixed configurations.
| Tuple Method | Description |
|---|---|
| count() |
Returns the number of times var appears in the list. General Form:
|
| index() |
Returns the index of the first element with the specified value (var). General Form:
|