Why Python expands output [[...]]

My lecturer asked a few questions in python, and this one confused me, I do not understand what is happening.

x = [[]] x[0].extend(x) 

Python tells me, after doing this, that x is [[...]] , which means ... ?

I get even more confused when the result of the following is only [[]]

 y = [] # equivalent to x[0] x = [[]] y.extend(x) 

If y calculated as [[]] , then shouldn't x just be [[[]]] ?

What is an extension? and what does it mean ... ?

+6
source share
1 answer

... indicates that the list contains a recursive loop, that is, at some level it contains something. This is because you extended x with x , so you essentially put x inside yourself.

In the second example, no ... because y is a separate object. Although it is equal to x[0] in that both are empty lists, they are not the same empty list.

+6
source

All Articles