What do ellipsis [...] mean in a list?(省略号 [...] 在列表中是什么意思?)
问题描述
I was playing around in python. I used the following code in IDLE:
p = [1, 2]
p[1:1] = [p]
print p
The output was:
[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.
EDIT:
- How is it represented in memory?
- What's its use? Examples of some cases where it is useful would be helpful.
- Any link to official documentation would be really useful.
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:
- 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
这篇关于省略号 [...] 在列表中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:省略号 [...] 在列表中是什么意思?
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- pytorch 中的自适应池是如何工作的? 2022-07-12
- python-m http.server 443--使用SSL? 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- padding='same' 转换为 PyTorch padding=# 2022-01-01
- 沿轴计算直方图 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01