I was checking tiny scripts and noticed this:
def foo( a = [] ):
a += [1]
print(a)
foo() # prints [1]
foo() # prints [1,1]
foo() # prints [1,1,1]
Why does this happen instead of printing only [1]
?
I was checking tiny scripts and noticed this:
def foo( a = [] ):
a += [1]
print(a)
foo() # prints [1]
foo() # prints [1,1]
foo() # prints [1,1,1]
Why does this happen instead of printing only [1]
?
You basically append element to your list. For example [1] + [1] would be [1, 1].