So, I was playing with the interpreter, and typed in the following:
In : 1 and 2 Out: 2 In : 1 and 5 Out: 5 In : 234324 and 2 Out: 2 In : 234324 and 22343243242 Out: 22343243242L In : 1 or 2 and 9 Out: 1
Initially I thought that it has to do with False and True values, because:
In : True + True Out: 2 In : True * 5 Out: 5
But that doesn’t seem related, because False is always 0, and it seems from the trials above that it isn’t the biggest value that is being outputted.
I can’t see the pattern here honestly, and couldn’t find anything in the documentation (honestly, I didn’t really know how to effectively look for it).
So, how does
int(x) [logical operation] int(y)
work in Python?
From the Python documentation:
x and yfirst evaluates
xis false, its
value is returned; otherwise,
yis evaluated and the resulting value
Which is exactly what your experiment shows happening. All of your
x values are true, so the
y value is returned.
It’s for every item in Python, it’s not dependent on the integer.
not x Returns True if x is True, False otherwise x and y Returns x if x is False, y otherwise x or y Returns y if x is False, x otherwise
1 is True, so it will return 2