Confusing […] List in Python: What is it?

前端 未结 9 2165
傲寒
傲寒 2020-11-29 10:52

So I was writing up a simple binary tree in Python and came across [...]

I don\'t believe this to be related to the Ellipsis object, more it seems to have something

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 11:33

    If you would have used a PrettyPrinter, the output would had been self explanatory

    >>> l = [1,2,3,4]
    >>> l[0]=l
    >>> l
    [[...], 2, 3, 4]
    >>> pp = pprint.PrettyPrinter(indent = 4)
    >>> pp.pprint(l)
    [, 2, 3, 4]
    >>> id(l)
    70327632
    

    In other words its something like

    enter image description here

提交回复
热议问题