The Classic Mutable Default Trap
def add_item(item, cart=[]):
cart.append(item)
return cart
print(add_item("apple"))
print(add_item("banana"))
What does the second print show?
Sign in to answer questions and track your progress
Sign Indef add_item(item, cart=[]):
cart.append(item)
return cart
print(add_item("apple"))
print(add_item("banana"))
What does the second print show?
Sign in to answer questions and track your progress
Sign In