Circular Reference with python lists

别说谁变了你拦得住时间么 提交于 2019-11-26 22:06:21

问题


Can someone explain this?

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

what is [...]?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/4196329/circular-reference-with-python-lists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!