Tuples

Tuples in Python are used to store multiple values together, similar to lists. The key difference is that tuples are immutable, which means you cannot change them after they are created. This makes tuples useful when you want to store a fixed set of values that should not be accidentally modified.

A tuple is created using parentheses, with items separated by commas. For example, you might store a coordinate as (x, y) or store a record like (name, age, city). You can also create a tuple without parentheses by using commas, but using parentheses is clearer and easier to read. Tuples can store different data types in the same structure, such as numbers and strings together.

Just like lists, tuples support indexing and slicing. Indexing starts from 0, and you can use negative indexing to access items from the end. This makes it easy to retrieve specific values from a tuple. You can also loop through a tuple using a for loop.

Tuples are commonly used in situations where data should remain constant. For example, you may return multiple values from a function and store them as a tuple. They are also used as keys in dictionaries when you need a compound key, because tuples are immutable and therefore hashable.

In data analysis, tuples appear often when working with grouped results, multi-level indexes, or structured outputs. They help keep related values together in a safe and lightweight way. If you need a collection of values that should not change, a tuple is a good choice.

Sets
Logical Operators

Get industry recognized certification – Contact us

keyboard_arrow_up