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


Leave a Reply

Your email address will not be published. Required fields are marked *