python – unpack a collection

If you have a collection of values in a list, tuple etc. Python allows you to extract the values into variables. This is called unpacking.

This is also called de-structuring in javascript.

example

fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
print(x)
print(y)
print(z)

Comments

Leave a Reply

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