Sobes.tech
Junior — Senior

Non-obvious consequences of using a mutable default argument

livecode

Task condition

Explain how passing a mutable object as a default parameter value (e.g., a list) in a Python function works and what side effects may occur with multiple function calls.

def add_item(item, lst=[]):
    lst.append(item)
    return lst

print(add_item(1))
Non-obvious consequences of using a mutable default… - sobes.tech