today I started studying Python and have a question. I want to append the list itself, for example
a = [0, 1, 2]
want to make [0, 1, 2, [0, 1, 2]]
by using function .append
a.append(a)
gets result like [0, 1, 2, [...]]
Is it the correct answer? I don't know why the answer has [...]
thing.
Also, what is the difference when I do this?
b = a.append(a)
print(b)
>> None
CodePudding user response:
[1, 2, 3, [...]]
is the correct answer. It is the way python represents recursive lists. Basically what that means isa = [1, 2, 3, [1, 2, 3, [1, 2, 3, [...]]]]
infinite times.list.append
returnsNone
.a.append(a)
therefore returnsNone
and if you store that inb
and print it,None
is the correct answer