Question discussion

What is the output of the following Python code?a, *b, c = [1, 2, 3, 4, 5] print(a, b, c)

2343Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following Python code?

a, *b, c = [1, 2, 3, 4, 5]
print(a, b, c)
  • A1 [2, 3, 4] 5
  • B1 2 5
  • C1 [2, 3] 4
  • DValueError: too many values to unpack
Correct answer: A

Explanation

The starred name collects all the middle items as a list, so a = 1, b = [2, 3, 4] and c = 5.

Discussion 0

Nobody has replied yet. Start the discussion!