Can anyone explain this behaviour in Python (2.7 and 3)
>>> a = "Monday" and "tuesday"
>>> a
'tuesday' # I expected this to be True
>>> a == True
False # I expected this to be True
>>> a is True
False # I expected this to be True
>>> a = "Monday" or "tuesday"
>>> a
'Monday' # I expected this to be True
>>> a == True
False # I expected this to be True
>>> a is True
False # I expected this to be True
I would expect that because I am using logic operators and
and or
, the statements would be evaluated as a = bool("Monday") and bool("tuesday")
.
So what is happening here?