Take a look at this code. All it does is return a list with appended parameter. In case no list is supplied, it defaults to an empty list and appends to it. Or is it???
1 2 3 4 5 6 |
def add_to_list(item, item_list=[]): item_list.append(item) return item_list add_to_list("gold") # expected: ["gold"] #actual: ["gold"] add_to_list("silver") # expected: ["silver"] #actual: ["gold","silver"] |
Look at the second result. We expected [“silver”] expecting the item to be appended to an empty list as […]