Sequence Unpacking

Sequence Unpacking:
So, to create a tuple, we treat it like a list(just remembering to change the brackets)
packing of tuple:

>>>tuple = (1,2,3,4)
The term for this is packing a tuple,because the data is "packed into" the tuple,all wrapped up and ready to go.So,to remove items from a tuple you simply unpack it.
Unpacking a tuple:
>>>first,second,third,fourth=tuple
>>>first
1
>>>second
2
>>>third
3
>>>fourth
4

1.Examples for tuples:

Employees = [(101, "Ayush", 22), (102, "john", 29), (103, "james", 45), (104,"Ben", 34)] 
print("----Printing list----"); 
for i in Employees: 
print(i) 
mployees[0] = (110, "David",22) 
print(); 
print("----Printing list after modification----"); 
for i in Employees: 
print(i) 
 
Output:
----Printing list----
(101, 'Ayush', 22)
(102, 'john', 29)
(103, 'james', 45)
(104, 'Ben', 34)

----Printing list after modification----

(110, 'David', 22)
(102, 'john', 29)
(103, 'james', 45)
(104, 'Ben', 34)
Translate »