Why the output of this code is false true? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why the output of this code is false true?

My_list=[([]),[()]] For i in My_list: Print (bool(i),end=" ")

9th Feb 2019, 4:53 PM
H.code
1 Answer
+ 2
The items in the list are [] and [()]. An empty list evaluates to False, a non-empty list to True (even if it contains only one element which evaluates to False). Note that ([]) is the same as []. If you want it to be a tuple with one element, use ([],) instead. ([],) would evaluate to True (non-empty tuple).
9th Feb 2019, 5:18 PM
Anna
Anna - avatar