Computer Science
Carefully read the given code fragments and figure out the errors that the code may produce.
t = ( 'a', 'b', 'c', 'd', 'e')
1, 2, 3, 4, 5, = t
Python Tuples
3 Likes
Answer
Output
SyntaxError: cannot assign to literal
Explanation
When unpacking a tuple, the LHS (left hand side) should contain a list of variables. In the statement, 1, 2, 3, 4, 5, = t
, LHS is a list of literals not variables. Hence, we get this error.
Answered By
2 Likes
Related Questions
Carefully read the given code fragments and figure out the errors that the code may produce.
t3 = (6, 7) t4 = t3 * 3 t5= t3 * (3) t6 = t3 * (3,) print(t4) print(t5) print(t6)
Carefully read the given code fragments and figure out the errors that the code may produce.
odd= 1,3,5 print(odd + [2, 4, 6])[4]
Carefully read the given code fragments and figure out the errors that the code may produce.
t = ( 'a', 'b', 'c', 'd', 'e') 1n, 2n, 3n, 4n, 5n = t
Carefully read the given code fragments and figure out the errors that the code may produce.
t = ( 'a', 'b', 'c', 'd', 'e') x, y, z, a, b = t