Tuple Methods
2 min read ·
Tuples in Python have very limited built-in methods compared to lists.
This is because tuples are immutable, so Python only provides methods that inspect data, not modify it.
There are only two tuple methods.
1. count()
What it does
Returns the number of times a specified value appears in the tuple.
Syntax
Example
2. index()
What it does
Returns the index of the first occurrence of a specified value.
Syntax
Example
index() with Start and End (Advanced)
You can limit the search range.
Syntax
Example
Error Handling with index()
If the value does not exist, Python raises an error.
Safe way:
Tuple Methods Summary Table
| Method | Purpose |
|---|---|
count() | Count occurrences of a value |
index() | Find index of a value |
Why Tuples Have Only Two Methods
- Tuples are immutable
- No methods to add, remove, or update items
- Safer for fixed data
- Faster than lists
Tuple vs List Methods
| Feature | Tuple | List |
|---|---|---|
| Mutable | No | Yes |
| Methods count | 2 | Many |
| Can modify data | No | Yes |
| Best use case | Fixed data | Dynamic data |