5

I tried to print a list which supposes to be(I think) a empty list, However I got a [[...]] instead. I tried to google it, but no luck. Futhermore, When I use slice to see what the hell is [...] in the strange list, I got the same [[...]], I guess there would be some kind of recursive, but what leads to it ?Anyone knows why?

ZhouQuan
  • 1,037
  • 2
  • 11
  • 19
  • 6
    Maybe post some code leading to that output? – Arpan Apr 06 '16 at 11:46
  • Thanks @Mat and Alasdair. I guess we should've looked for dupes before answering... but our answers add a _little_ bit to the info given at the dupe target. ;) But I guess the new question title is not search-engine friendly, even though it's otherwise clear. – PM 2Ring Apr 06 '16 at 11:52

3 Answers3

8

You are correct. It's a list that contains itself recursively. Here's a simple way to create such a list:

a = []
a.append(a)
print(a)

output

[[...]]
PM 2Ring
  • 54,345
  • 6
  • 82
  • 182
4

That means a list contains itself:

a = []
a.append(a)
print(a)
HYRY
  • 94,853
  • 25
  • 187
  • 187
3
>>> a=[]
>>> a.append(a)
>>> a
[[...]]

This is one way to get that -- a list with one element, namely itself.

Such a structure can't be printed (it recurses forever) so Python prints ellipsis to mean "and so on".

RemcoGerlich
  • 30,470
  • 6
  • 61
  • 79