DEV Community

Cover image for Day 10 of Learning Python: Tuples
Mary Nyandia
Mary Nyandia

Posted on

Day 10 of Learning Python: Tuples

Creating Tuples
Tuples are similar to lists but immutable. Once created, their contents cannot be changed. This makes them ideal for fixed collections of data, like coordinates.

Accessing Elements
Tuples use indexing just like lists. You can retrieve elements by position, making them easy to work with.

Immutability
The key feature of tuples is immutability. This ensures data remains constant, which is useful for values that should never change, like configuration settings.

Single‑Item Tuples
To create a tuple with one item, you must include a trailing comma. Without it, Python interprets the value as just a number in parentheses.

Unpacking Tuples
Tuples can be unpacked into separate variables, allowing you to assign multiple values at once. This is a neat way to handle grouped data.

Top comments (0)