CBSE Class 11 Computer Science Question 68 of 114

Tuples — Question 5

Back to all questions
5
Question

Question 1(e)

Find the output generated by following code fragments :

a, b, c, d, e = (p, q, r, s, t) = t1
Answer
Output

Assuming t1 contains (1, 2.0, 3, 4.0, 5), the output will be:

a = 1
p = 1

b = 2.0
q = 2.0

c = 3
r = 3

d = 4.0
s = 4.0

e = 5
t = 5
Explanation

The statement unpacks the tuple t1 into the two variable lists given on the left of t1. The list of variables may or may not be enclosed in parenthesis. Both are valid syntax for tuple unpacking. t1 is unpacked into each of the variable lists a, b, c, d, e and p, q, r, s, t. The corresponding variables of the two lists will have the same value that is equal to the corresponding element of the tuple.