What is A Tuple in Python

Definition

A tuple is an ordered, immutable collection in Python, written in parentheses, e.g., (1, 2, 3), suitable for fixed data.

Immutable Nature

Tuples cannot be modified after creation. This immutability makes them reliable for constant data storage.

Heterogeneous Data

Tuples can store different data types in the same sequence, such as (42, "hello", True).

Access by Index

Access tuple elements using zero-based indexing, e.g., my_tuple[0] retrieves the first element.

Compact and Fast

Tuples use less memory and are faster than lists, making them ideal for read-only collections.

Common Operations

Operations like slicing, iteration, and concatenation are supported, but modification operations like appending are not.