+ 1
Boolean login in Python on lists and tuples
Hi, why is the output of this code: False True and not False False? my_list = [([]),[()]] for i in my_list: print (bool(i), end=" ")
1 ответ
+ 9
The trick here is, [] is an empty list but [()] isn't and parentheses"( )" around any entity is neglected until it contains a comma ", ", in which case it'd be a tuple.
In short: ([]) is [], length 0 hence False and [()], length 1, hence True.