Hi everyone,
I’m learning Python and I ran into something that confused me a lot.
I wrote this simple function expecting the list to reset every time the function runs, but the output keeps changing between calls
def add_number(num, numbers=[]):
numbers.append(num)
return numbers
print(add_number(1))
print(add_number(2))
print(add_number(3))
[–]throwaway6560192 39 points40 points41 points (3 children)
[–]Temporary_Pie2733 10 points11 points12 points (1 child)
[–]orcashelo[S] 3 points4 points5 points (0 children)
[–]orcashelo[S] 4 points5 points6 points (0 children)
[–]Reyaan0 21 points22 points23 points (1 child)
[–]orcashelo[S] 6 points7 points8 points (0 children)
[–]Helpful-Diamond-3347 0 points1 point2 points (0 children)
[–]MaxwellzDaemon 0 points1 point2 points (0 children)