Why does 'or' only use the first value in python?
b = 'a' print(b==('b' or 'a'))
You will get
False if you enter this code.
But if you change the order like this:
b = 'a' print(b==('a' or 'b'))
So, why does
or in this code only consider the first value of the two?
I think the upper code should also return
Try evaluating the following expression in the python REPL:
'a' or 'b'
'a', because the
oroperator short-circuits; that is, it returns the first truthy argument it finds, in this case,
'b'are truthy, so you're simply getting whichever one of those you put first.
If I understand your code correctly, you probably wanted to write:
b = 'a' print(b in ('a', 'b'))
This checks if
bequals one of