The None-Sentinel Fix
def add_item(item, cart=None):
cart = cart if cart is not None else []
cart.append(item)
return cart
print(add_item("apple"))
print(add_item("banana"))
What does the second print show, and why does this version avoid the bug from cart=[]?
Sign in to answer questions and track your progress
Sign In