ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
import time
def stamp(t=[]):
    t.append(len(t))
    return t
print(stamp(), stamp(), stamp.__defaults__)
  1. A. [0] [0, 1] ([0, 1],)
  2. B. [0, 1] [0, 1] ([0, 1],)
  3. C. [0] [0] ([],)
  4. D. [0, 1] [0, 1] ([],)

Correct answer: B. [0, 1] [0, 1] ([0, 1],)

Both calls return the very same default list, and print receives its arguments only after both calls ran, so both show [0, 1]. __defaults__ holds that same mutated list object.

More Python Programming questions

Exams that ask this topic