Computer Science
Find the output generated by following code fragments :
a, b, c, d, e = (p, q, r, s, t) = t1
Python Tuples
5 Likes
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.
Answered By
1 Like
Related Questions
Find the output generated by following code fragments :
(a, b, c, d) = (1, 2, 3)
Find the output generated by following code fragments :
a, b, c, d = (1, 2, 3)
a, b, c, d, e = (p, q, r, s, t) = t1
What will be the values and types of variables a, b, c, d, e, p, q, r, s, t if t1 contains (1, 2.0, 3, 4.0, 5) ?
Find the output generated by following code fragments :
t2 = ('a') type(t2)