Python Tutorial

Unpacking a Tuple in Python Explained With Examples

How to Unpack Tuples in Python?

Normally, when we create a tuple, we attach values to it. A tuple is "packed" in this way. However, we can also extract the values and store them in variables. This is referred to as the unpacking of tuples in Python.

Example:

fruits = ("cranberry", "blueberry", "apricot")

(green, yellow, red) = fruits

print(green)

print(yellow)

print(red)

Output:

cranberry
blueberry
apricot
Did you find this article helpful?