Computer Science
Carefully read the given code fragments and figure out the errors that the code may produce.
t = ( 'a', 'b', 'c', 'd', 'e')
a, b, c, d, e, f = t
Python Tuples
1 Like
Answer
Output
ValueError: not enough values to unpack (expected 6, got 5)
Explanation
In tuple unpacking, the number of elements in the left side of assignment must match the number of elements in the tuple.
Here, tuple t contains 5 elements where as left side contains 6 variables which leads to mismatch while assigning values.
Answered By
1 Like
Related Questions
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
What would be the output of following code if
ntpl = ("Hello", "Nita", "How's", "life?") (a, b, c, d) = ntpl print ("a is:", a) print ("b is:", b) print ("c is:", c) print ("d is:", d) ntpl = (a, b, c, d) print(ntpl[0][0]+ntpl[1][1], ntpl[1])
Predict the output.
tuple_a = 'a', 'b' tuple_b = ('a', 'b') print (tuple_a == tuple_b)