What is the difference between the two  statements?
(i) t=(‘a’,’b’,’c’)
(ii) a,b,c=t 

 
Answer:

The difference between the two statements is:

  • The first statement (i) creates a tuple with three elements (‘a’, ‘b’, and ‘c’) and assigns it to a variable t. 
  • The second statement (ii) unpacks the tuple t and assigns its elements to three variables a, b, and c. Unpacking is a way of assigning multiple values to multiple variables in one line of code.
Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.