Interest Ask!
Here is the bytecode from 'a' in 'abc' is True :
>>> import dis >>> dis.disassemble((lambda: 'a' in 'abc' is True).func_code) 2 0 LOAD_CONST 1 ('a')
And compare with that of ('a' in 'abc') is True :
>>> import dis >>> dis.disassemble((lambda: ('a' in 'abc') is True).func_code) 1 0 LOAD_CONST 1 ('a')
So, the expression 'a' in 'abc' is True looks something like this:
>>> 'a' in 'abc' and 'abc' is True
This seems to be the result of a chain of statements: fooobar.com/questions/165474 / ... - the same magic that makes work 1 < 5 < 10 workable.
Very interesting!
(Note: this was done with CPython 2.7.2)
source share