Search⌘ K
AI Features

Tuples

Explore how to create and manipulate tuples in Python, including packing and unpacking values, accessing elements through indexing and slicing, and using built-in functions like divmod. Understand the immutability of tuples and how they can serve as grouped units of information in your Python programs.

Definition

A tuple consists of two or more values separated by commas and enclosed in parentheses, for example, ("John", 23).

Python 3.5
tup1 = (1, 2, 3) # Tuple of integers
print(tup1)
tup2 = (7, "Great", 1.52, True) # Tuple of mixed data types
print(tup2)

Tuples are useful for keeping a small number of values together as a single unit. For example, you might want to write a function that returns the x-y coordinates of an object, or the largest and smallest values in a ...