ProgrammingHardAccenture pattern

What is printed?

What is printed?
def f():
    return 1, 2, 3
a, b, c = f()
print(a, b, c)
x = f()
print(type(x), x)
  1. A. 1 2 3 <class 'list'> [1, 2, 3]
  2. B. 1 2 3 <class 'tuple'> (1, 2, 3)
  3. C. (1, 2, 3) <class 'tuple'> (1, 2, 3)
  4. D. 1 2 3 <class 'tuple'> (1, 2, 3, 3)

Correct answer: B. 1 2 3 <class 'tuple'> (1, 2, 3)

return 1, 2, 3 packages the values into a tuple. Unpacking it into a,b,c works normally. Without unpacking, x just receives that same tuple directly, type tuple.

More Python Programming questions

Exams that ask this topic