ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
x, *y = "hello"
print(x, y)
  1. A. h ello
  2. B. h ['e', 'l', 'l', 'o']
  3. C. 'h' 'ello'
  4. D. hello []

Correct answer: B. h ['e', 'l', 'l', 'o']

Unpacking a string iterates its characters; x takes the first character 'h', and the starred name *y collects the rest as a LIST of individual characters, not a substring.

More Python Programming questions

Exams that ask this topic