Search code examples
pythonself-reference

What is the meaning of [...] in python?


Instead of a list with some objects in it, I get [...] whenever I run my code. I'd like to know what it means, in order to debug my code.


Solution

  • That most probably is a reference to the object itself. Example:

    In [1]: l = [0, 1]
    
    In [2]: l.append(l)
    
    In [3]: l
    Out[3]: [0, 1, [...]]
    

    In the above, the list l contains a reference to itself. This means, you can endlessly print elements within it (imagine [0, 1, [0, 1, [0, 1, [...]]]] and so on) which is restricted using the ... IMO, you are incorrectly appending values somewhere in your code which is causing this.

    A more succinct example:

    In [1]: l = []
    
    In [2]: l.append(l)
    
    In [3]: l
    Out[3]: [[...]]