1. Tuples as Immutable Records
Fixed Structure and Memory Efficiency
- Tuples represent heterogeneous records of fixed length (e.g., coordinates (x, y, z), database rows).
- CPython optimizes tuples: because they cannot grow, there is no over-allocation buffer, reducing memory overhead.
- Single-element tuples require a trailing comma: `single = (42,)`. Without the comma, `(42)` is just parenthesized integer 42.
point = (10, 20, 30)
# point[0] = 15 -> TypeError: 'tuple' object does not support item assignment
print("Tuple:", point)