0

Python List append

Can you explain the behind the scenes of the output of this code ? a = [1,2] b = [1,2] a.append (b) b.append (a) print(a) print(b) https://code.sololearn.com/cCFgkfxZwrUz/?ref=app

23rd Jan 2020, 6:08 AM
Sri Lakshmi
Sri Lakshmi - avatar
2 Réponses
+ 3
Both append statements add a third element to the list, which is a reference to the other list. Therefore it creates an endless circular reference between these two lists. Python detects this infinite loop and expresses it with the [...] or Ellipsis symbol. Check out this thread too: https://www.sololearn.com/discuss/1874398/?ref=app
23rd Jan 2020, 6:11 AM
Tibor Santa
Tibor Santa - avatar
+ 2
Thank you Tibor Santa
23rd Jan 2020, 6:46 AM
Sri Lakshmi
Sri Lakshmi - avatar