def foo(i, x=[]):
x.append(x.append(i))
return x
for i in range(3):
y = foo(i)
print(y)
print(y)
this results in
[0, None]
[0, None, 1, None]
[0, None, 1, None, 2, None]
[0, None, 1, None, 2, None]
Why is the None
being appended in the list? I checked some threads on this topic, unfortunately I couldn't still understand why None
is being printed.
If I replace x.append(x.append(i))
with just x.append(i)
the None
goes away. That made sense, but I'm still unclear why the x.append(x.append(i))
adds a None
.