+ 4

a=[] a.append(a) print(a) out:[[...]]

a=[] a.append(a) print(a) out: [[...]] What is this output?

11th Sep 2021, 2:37 PM
Arsalan [Inactive]
Arsalan [Inactive] - avatar
8 odpowiedzi
+ 4
Hi Arsalan! This is called Python ellipsis ... It's a special object in python, a kind of a placeholder You can refer this article to understand its concept clearly. https://python.land/python-ellipsis
11th Sep 2021, 3:01 PM
Python Learner
Python Learner - avatar
+ 2
Tanvir Salehin So why doesn' this one output that answer? a = 3 a += a print(a) Out: 6
11th Sep 2021, 2:51 PM
Arsalan [Inactive]
Arsalan [Inactive] - avatar
+ 1
Arsalan I am sorry, that was not recursion, and the list is not infinite. 😓😓😓 Actually what happens is that a, or an empty list appends another empty list in it (though the same list is appended, it is treated like an ordinary empty list ig). So a 2 dimensional list is created that has an empty list in it. Idk for what reason there are 3 dots (...) in the appended list. Sorry for my wrong answer. Correct me if I am wrong. Thank you
11th Sep 2021, 2:57 PM
Tanvir Salehin
Tanvir Salehin - avatar
+ 1
Yeah, You append the same variable
11th Sep 2021, 3:34 PM
CGO!
CGO! - avatar
0
That's an empty list in a list. What's going on? a=[] gives an emty list. And if you do e. g. a.append(1) it looks like this [1], it's normal, isn't it. And now the 1 will be an empty list named a a.append(a) This shows now an empty list in the list instead of the 1 before - > [ [ ] ]
11th Sep 2021, 2:56 PM
Coding Cat
Coding Cat - avatar
0
Coding Cat [Mouse searching] Idk for what reason, I thought there were infinite lists in that list. (Maybe because of the 3 dots)
11th Sep 2021, 2:58 PM
Tanvir Salehin
Tanvir Salehin - avatar
0
It's like pass right
13th Sep 2021, 8:21 AM
Mr.Dark
Mr.Dark - avatar
- 1
.....Recursion....
11th Sep 2021, 2:42 PM
Tanvir Salehin
Tanvir Salehin - avatar