I'm learning the language python. And although it is very simple indeed, I got some unexpected results using logic operators both in IDLE and in python.
I made a simple test in IDLE like this:
(2 or 10) in range(1,6)
And my response was True
. So far so good. However, if I do this:
(10 or 2) in range(1,6)
My response is False
. Even though "2" is clearly inside the range(1,6)
.
I made the same test in PyCharm and here are my responces:
if (2 or 10) in range(1,6):
print("True")
else:
print("False")
Result: True
if (10 or 2) in range(1,6):
print("True")
else:
print("False")
Result: False
if 2 or 10 in range(1,6):
print("True")
else:
print("False")
Result: True
if 10 or 2 in range(1,6):
print("True")
else:
print("False")
Result: True
I would like to know the logic behind it please.