Python Tuples

Tuples are an ordered, immutable sequence of Python objects. They are similar to lists, but cannot be changed after creation.

Key Characteristics

Creating Tuples

Tuples are created using parentheses ().


        my_tuple = (1, "hello", 3.14)
    

Accessing Elements

Elements are accessed using indexing, similar to lists.


        print(my_tuple[0])  # Output: 1
    

Tuple Operations

Common tuple operations include:

When to use Tuples

Tuples are useful when you need to ensure that data remains constant. Common use cases include representing fixed records or returning multiple values from a function.

Related Topics