A tuple is an ordered, immutable (unchangeable) collection of items.
It can store different data types, just like a list.

✅ Example:
t1 = (10, 20, 30)
t2 = ("Sakshi", 9.4, True)
✅ Empty Tuple:
empty = ()
✅ Single Element Tuple (don’t forget the comma):
single = (5,) # Tuple
not_tuple = (5) # Just an integer
tuple1 = (1, 2, 3)
tuple2 = ("apple", "banana", "cherry")
tuple3 = tuple([10, 20, 30]) # from list
✅ Example:
colors = ("red", "green", "blue", "yellow")
print(colors[0]) # red
print(colors[-1]) # yellow
print(colors[1:3]) # ('green', 'blue')
You cannot change or delete tuple elements.
❌ Example (Error):
t = (1, 2, 3)
t[0] = 10 # TypeError
✅ You can reassign the variable though:
t = (1, 2, 3)
t = (4, 5, 6) # New tuple created
| Operation | Example | Output |
|---|---|---|
| Concatenation | (1, 2) + (3, 4) | (1, 2, 3, 4) |
| Repetition | ("Hi",) * 3 | ('Hi', 'Hi', 'Hi') |
| Membership | "a" in ("a", "b") | True |
| Length | len(t) | — |
| Index | t.index(x) | returns index of first occurrence |
| Count | t.count(x) | counts how many times x appears |
✅ Example:
t = (1, 2, 2, 3, 4)
print(len(t)) # 5
print(t.count(2)) # 2
print(t.index(3)) # 3rd position → index 3
✅ Example:
fruits = ("apple", "banana", "cherry")
for f in fruits:
print(f)
✅ Example:
student = ("Sakshi", 9.4, "CSE")
name, sgpa, branch = student
print(name) # Sakshi
print(sgpa) # 9.4
✅ Example:
nested = ((1, 2), (3, 4), (5, 6))
print(nested[1][0]) # 3

| Function | Description | Example |
|---|---|---|
| len() | Number of elements | len(t) |
| max() | Largest value | max((10, 20, 5)) → 20 |
| min() | Smallest value | min((10, 20, 5)) → 5 |
| sum() | Sum of numeric values | sum((1,2,3)) → 6 |
| sorted() | Returns sorted list | sorted((3,1,2)) → [1,2,3] |
✅ Tuples are:
Faster than lists (because immutable).
Memory efficient.
Hashable (can be used as keys in dictionaries).
Safe (data can’t be modified accidentally).