I know that one has to be careful with mutable arguments like lists applied to function calls, so that things like this won't accidentally happen:
def add_item(list2): list2.append(99) return list2 list1 = [1, 2, 3] list3 = add_item(list1) print list1 # [1, 2, 3, 99] oops! print list3 # [1, 2, 3, 99] expected
Can somebody explain to me why exactly why this happens? Also, can this be usefull?