Loading section...

Tuples: Immutable Sequences

Tuples look similar to lists but have one critical difference: they cannot be changed after creation. Once you create a tuple, you cannot add, remove, or modify its elements. This immutability is not a limitation - it is a feature that makes your code safer and more predictable. Think about data that should never change: database connection parameters, geographic coordinates, RGB color values, or API response codes. If you accidentally modify such data, bugs can be extremely difficult to track down. Tuples prevent this entire category of bugs by making modification impossible. Notice that we still use square brackets to access tuple elements, just like lists. The difference is only in what operations are allowed. Reading is fine; writing is forbidden. Attempting to modify a tuple raises a