Computer Science
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) ?
Python Tuples
7 Likes
Answer
Variable | Value | Type |
---|---|---|
a | 1 | int |
b | 2.0 | float |
c | 3 | int |
d | 4.0 | float |
e | 5 | int |
p | 1 | int |
q | 2.0 | float |
r | 3 | int |
s | 4.0 | float |
t | 5 | int |
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
2 Likes
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, e = (p, q, r, s, t) = t1
Find the output generated by following code fragments :
t2 = ('a') type(t2)
Find the output generated by following code fragments :
t3 = ('a',) type(t3)