+ 1

Can anyone say why we have got the following output for the given code ?

----------- Input : ----------- a=[1,2] a.append(a) print(a) print(a[2]) print(a[2][2]) print(a[2][2][2]) print(a!=a[2][2][2]) ------------- Output : ------------- [1,2,[...]] [1,2,[...]] [1,2,[...]] [1,2,[...]] False The code is given below ! 👇👇 https://code.sololearn.com/cVRtV2EtRX2K/?ref=app

29th Sep 2019, 7:01 AM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
2 Answers
+ 6
By appending a to itself u r creating a potentially endless loop. a[2] is assigned to the same list object as a. So by trying to access it you always access the same list again.
29th Sep 2019, 8:12 AM
Thoq!
Thoq! - avatar