Is there a difference? Yes: one works, and the other doesn't.
if response == False
is only true if the actual value of response
is False
. For an empty string, that is not the case.
if not response
, on the other hand, verifies if response
is falsey; that is, it is one of the values that Python accepts as false in a boolean context, which includes None, False, the empty string, the empty list, and so on. It is equivalent to if bool(response) == False
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…