What is tuple packing in python? | What is tuple unpacking in python?

What is tuple packing?

A tuple is one of 4 built-in collection data types and the other three are list, set, dictionary.

We can only apply two methods to tuple aa it is immutable. We saw everything in detail about tuple in the previous article, now let us see what is packing?

In tuple packing, we assign tuple items to a single variable or we assign multiple items to multiple variables and at the end, we assign all those multiple items to a single variable.

Code: –

what is packing  in python?

Output: –

packingoutput

We have taken 4 variables a, b, c and d and in those variables, we have passed data, and all those 4 variables we passed to t4. And in this way, we achieve tuple packing.

What is tuple unpacking?

This is completely the opposite of tuple packing in this we assign each element of a tuple into different variables explicitly.

Code: –

What is tuple unpacking?
What is tuple unpacking?

Output: –

unpacking output

Here we have defined a tuple variable t2 and passed tuple items to it and then we have applied the concept of unpacking to it, that is the first item goes to a variable second item goes to the b, and so on. And this is how we achieve tuple unpacking.

Waqar Khan

Hello, everyone, I am Waqar Khan. I have done my B.tech in Computer Science. I love to write about Computer Informational blogs. Before write I did proper research on it. Hope you like our blogs. Thank you.

Related Posts

Leave a Reply

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