Sobes.tech
Junior — Senior

What output will a program with a function that uses a mutable default parameter produce?

livecode

Task condition

Determine what will be printed to the console after executing the given code. The function extend_list takes a list as a default argument, which can cause unexpected accumulation of elements on subsequent calls.


def extend_list(value, Lst=[]):
    Lst.append(value)
    return Lst

list1 = extend_list(10)
list2 = extend_list(123, [])
list3 = extend_list('a')

print(list1)
print(list2)
print(list3)