I did several Boolean Comparisons:
>>> (True or False) is True
True
>>> (True or False) == True
True
It sounds like ==
and is
are interchangeable for Boolean-values.
Sometimes it's more clear to use is
I want to know that:
Are True
and False
pre-allocated in python?
Is bool(var)
always return the same True
(or False
) with the pre-allocated True
(or False
)?
Is it safe to replace ==
with is
to compare Boolean-values?
It's not about Best-Practice.
I just want to know the Truth.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…