Program - Don't use mutable objects as default arguments for functions!


Topic: Program - Don't use mutable objects as default arguments for functions!

Solution

def append_to_list(value, def_list=[]):
    def_list.append(value)
    return def_list
my_list = append_to_list(1)
print(my_list)
my_other_list = append_to_list(2)
print(my_other_list)



List all Python Programs