Why do we still need immutability when memory is not shared?

Python’s mutable default arguments take this to a whole different level of surprise…

From https://docs.python-guide.org/writing/gotchas/

def append_to(element, to=[]):
    to.append(element)
    return to

my_list = append_to(12)
print(my_list) #Result: [12]

my_other_list = append_to(42)
print(my_other_list) #Result: [12, 42]
14 Likes