Tuple
Tuples are immutable sequences in Python. They are frequently used for fixed collections of heterogeneous data. Named tuples add field names for more readable code. This guide covers both regular and named tuples. The guide walks through Tuple Basics & Immutability, Packing & Unpacking, Tuple Operations, Named Tuples, Typed Named Tuples. Create tuples with parentheses `(1, 2, 3)` or without `1, 2, 3`. A single-element tuple needs a trailing comma: `(1,)`. Tuples are immutable — you cannot change, add, or remove elements after creation. They are hashable if all elements are hashable. Tuple packing: `point = 3, 4`. Unpacking: `x, y = point`. Extended unpacking (Python 3+): `first, *rest = (1, 2, 3, 4)` gives first=1, rest=[2,3,4]. Swapping values: `a, b = b, a` uses tuple packing/unpacking internally. Access elements by index: `t[0]`, `t[-1]`. Slice: `t[1:3]`. Concatenate: `t1 + t2`. Repeat: `t * 3`. Membership: `x in t`. Length: `len(t)`. Count: `t.count(x)`. Find index: `t.index(x)`. Sort via `sorted(t)` returning a list.