+ 4
a=[] a.append(a) print(a) out:[[...]]
a=[] a.append(a) print(a) out: [[...]] What is this output?
8 Answers
+ 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
+ 2
Tanvir Salehin
So why doesn' this one output that answer?
a = 3
a += a
print(a)
Out:
6
+ 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
+ 1
Yeah, You append the same variable
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
- > [ [ ] ]
0
Coding Cat [Mouse searching]
Idk for what reason, I thought there were infinite lists in that list. (Maybe because of the 3 dots)
0
It's like pass right
- 1
.....Recursion....