列表中的省略号是什么意思? [英] What do ellipsis [...] mean in a list?

查看:313
本文介绍了列表中的省略号是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩python.我在IDLE中使用了以下代码:

I was playing around in python. I used the following code in IDLE:

p  = [1, 2]
p[1:1] = [p]
print p

输出为:

[1, [...], 2]

这是什么[…]?有趣的是,我现在可以将其用作直到无穷大的列表列表.

What is this […]? Interestingly I could now use this as a list of list of list up to infinity i.e.

p[1][1][1]....

我可以根据需要编写以上内容,并且仍然可以使用.

I could write the above as long as I wanted and it would still work.

  • 它在内存中如何表示?
  • 它的用途是什么?在某些情况下有用的示例可能会有所帮助.
  • 任何指向官方文档的链接都将非常有用.

推荐答案

这意味着您创建了一个嵌套在其内部的无限列表,该列表无法打印. p包含p,其中p ...依此类推. [...]表示法是一种让您知道这一点并告知它无法表示的方式!看看@ 6502的答案,可以看到一张很好的图片,显示正在发生的事情.

It means that you created an infinite list nested inside itself, which can not be printed. p contains p which contains p ... and so on. The [...] notation is a way to let you know this, and to inform that it can't be represented! Take a look at @6502's answer to see a nice picture showing what's happening.

现在,关于编辑后的三个新项目:

Now, regarding the three new items after your edit:

  • 答案似乎涵盖了
  • Ignacio的链接描述了一些可能的用途
  • 与编程语言相比,这是数据结构设计的主题,因此在Python的官方文档中不太可能找到任何参考文献
  • This answer seems to cover it
  • Ignacio's link describes some possible uses
  • This is more a topic of data structure design than programming languages, so it's unlikely that any reference is found in Python's official documentation

这篇关于列表中的省略号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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