$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · hard · #41

What is printed after both calls?

def add(x, lst=[]):
    lst.append(x)
    return lst
print(add(1))
print(add(2))
  1. [1] [2]
  2. [1, 2] [1, 2]
  3. [1] [1]
  4. [1] [1, 2]
The default list is shared across calls, so it accumulates.
Play Problem Solving ▸