3 ms·
Yep and that's also the source of the footgun: def foobar(my_list=[]): my_list.append(42) A cursory glance suggests this function appends a number to an emp
by thrtythreeforty 4y ago
Yep and that's also the source of the footgun:
def foobar(my_list=[]):
my_list.append(42)
A cursory glance suggests this function appends a number to an empty list every time it's run. But actually, the default argument is evaluated once when the function is defined, so calling this function repeatedly will continue to append to that same list.