What do ellipsis […] mean in a list?

前端 未结 5 1512
甜味超标
甜味超标 2020-11-22 10:46

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, [.         


        
5条回答
  •  鱼传尺愫
    2020-11-22 11:10

    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

提交回复
热议问题