I understand that I can test if a list is empty like this:
l = []
if not l:
print("empty")
But I do not understand why the next code isn't equivalent:
if l == False:
print("empty")
I understand that I can test if a list is empty like this:
l = []
if not l:
print("empty")
But I do not understand why the next code isn't equivalent:
if l == False:
print("empty")
l
itself is list
type so comparing it with boolean will always return False
not l
is boolean expression so it will return True
sometimes depending on if l
is empty or not
>>>l = []
>>>type(l)
<type 'list'>
>>>l == True
False
>>>l == False
False
>>>
>>>
>>> type(not l)
<type 'bool'>
>>> (not l) == False
False
>>> (not l) == True
True