In your first code:
x = [0, 1, 2, 3, 4]
x.append(x)
print(x)
output
Output[0, 1, 2, 3, 4, [...]]
|
---|
You are appending the list x to itself. When you try this, x essentially includes a connection with itself. However, Python avoids endless recursion in printing lists by using representing the self-reference with [...] to signify that x incorporates a reference to itself. It does not recursively print the whole list interior itself to prevent infinite output.
So, the output [zero, 1, 2, three, four, [...]] approach that the listing x includes all its authentic factors (zero, 1, 2, 3, four) and a reference to itself, represented with the aid of [...].
In your second code:
x = [0, 1, 2, 3, 4]
y = [0, 1, 2, 3, 4]
x.append(y)
print(x)
Output[0, 1, 2, 3, 4, [0, 1, 2, 3, 4]]
|
You are appending a new listing 'y' to 'x'. In this example, x carries its original factors '(0, 1, 2, 3, 4)' and any other list 'y'. This results inside the output '[0, 1, 2, 3, 4, [0, 1, 2, 3, 4]]', which makes feel due to the fact x now carries its original factors and a connection with the listing y, which is outlined as '[0, 1, 2, 3, 4]'.
In overview, the difference in output is due to how Python handles appending a listing to itself (represented as [...]) versus appending any other list (which is outlined as the contents of the appended list).