Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我打印了一个列表的内容,我得到了以下输出:
[[...], [...], [...], [...], [...], [...]]
这些奇怪的点是什么?
我使用了 python 2.7.3
可能你不小心构建了一个包含对自身的引用的列表(或者这里有很多引用):
>>> a = ['x'] >>> a ['x'] >>> a[0] = a >>> a [[...]]
使用三个点是为了使字符串表示不会淹没在递归中。您可以使用idandis运算符来验证这一点:
id
is
>>> id(a) 165875500 >>> id(a[0]) 165875500 >>> a is a[0] True