Coming from javascript, I found pretty bizarre this behaviour:
>>> empty_list = []
>>> empty_list == True
False
>>> empty_list is True
False
>>> empty_list is False
False
>>> empty_list == False
False
And on the other hand:
>>> one_list = [1]
>>> one_list is False
False
>>> one_list is True
False
>>> one_list == False
False
>>> one_list == True
False
Actually, I expected that since:
if []:
pass # This never done
and
if [4]:
pass # This is always done
and
>>> not []
True
>>> not [1]
False
A list would convert to a boolean.
I am aware that
>>> bool([])
False
>>> bool([1])
True
So I wonder why not
and if
perform this conversion, whereas nor in
nor ==
do
Is there any formal explanation for this?