0

What is "[...]" in list ?Why the second output doesn't have double list ?I know that a and b share same id but, Why this is happening?

a = [1, 2, 3]
b =a
b.append(4)
print(a)

output :[1, 2, 3, 4]


a.append(b)
print(b)

output :[1, 2, 3, 4, [...]]#what happend here ?
SOORYADEV
  • 39
  • 1
  • 7

1 Answers1

0

Okay i don't know that this is best answer or not Please do correct me if i am wrong.

Try This :

print(b[4][4])  # you can add as many [4] you want and i used [4] because it isthe position of [...] .

The output will be same **Output:[1, 2, 3, 4, [...]] **

So i tried getting address of all 'b' as well as 'b[4]' , 'b[4][4]' ......

using:

print(id(b))
print(id(b[4]))
print(id(b[4][4]))

## All these will return the same address.

So, the list inside list is the same list (a or b) and it continues, this is why you are getting those '...'

Abhishek Chauhan
  • 365
  • 3
  • 11