打印列表,子列表内出现三个点 [英] Printed a list, three dots appeared inside sublists

查看:38
本文介绍了打印列表,子列表内出现三个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打印出列表的内容,并得到以下输出:

I printed out the contents of a list, and i got the following output:

[[...], [...], [...], [...], [...], [...]]

这些奇怪的点是什么?

我使用了python 2.7.3

I used python 2.7.3

推荐答案

可能是您不小心建立了一个包含对自身的引用(或此处有很多引用)的列表:

Probably you accidentally built a list containing a reference to itself (or here, lots of references):

>>> a = ['x']
>>> a
['x']
>>> a[0] = a
>>> a
[[...]]

使用了三个点,以使字符串表示不会在递归中被淹没.您可以使用 id is 运算符进行验证:

The three dots are used so that the string representation doesn't drown in recursion. You can verify this by using id and the is operator:

>>> id(a)
165875500
>>> id(a[0])
165875500
>>> a is a[0]
True

这篇关于打印列表,子列表内出现三个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆