+ 4
Can you explain this output?
x=([]) print(bool(x)) #output=False,but why... y=[()] print(bool(y)) #output=Ture,but why.... can anyone explain this.
5 Respostas
+ 5
The first, x, is an empty list. The second list, y, is not empty.
print(bool(([],))
will return true as it is a tuple containing an empty list.
+ 3
Good question!
[()] is not empty because it is a list containing a tuple.
But, ([]) becomes just [] because python thinks there are just extra parentheses. However, if you try putting a comma after the list like so:
([],) or just [],
Suddenly it becomes a tuple containing an empty list.
Hope this helped :)
- 1
mmm
- 2
hhhhiolhouv ytiv
- 3
hj