Circular Reference with python lists

后端 未结 3 760
旧时难觅i
旧时难觅i 2020-12-07 03:29

Can someone explain this?

>>> x=x[0]=[0]
>>> x
[[...]]
>>> x is x[0]
True
>>> x[0][0][0][0][0][0][0]
[[...]]
>>>         


        
相关标签:
3条回答
  • 2020-12-07 03:34

    That's just Python telling you that you have a circular reference; it's smart enough not to enter an infinite loop trying to print it out.

    0 讨论(0)
  • 2020-12-07 03:46

    iPython will do this:

    [<Recursion on list with id=38505216>]

    It's the same thing; the interpreter telling you that you have a recursive data structure.

    0 讨论(0)
  • 2020-12-07 03:53

    It's output by the method responsible for generating the representation of the structure. It represents a recursive structure, elided since it can be nested infinitely.

    0 讨论(0)
提交回复
热议问题