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
>Solution :
-
[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.appendreturnsNone.a.append(a)therefore returnsNoneand if you store that inband print it,Noneis the correct answer