It is called a chain of operators . Whenever you have an expression of type A op1 B op2 C with comparisons of op1 and op2 , it "translates" to A op1 B and B op2 C (In fact, he evaluates B only once).
Note: the comparison operator includes in , not in , is , is not ! (e.g. a is b is not None means a is b and b is not None ).
If you want to look at the bytecode, you can use the dis module:
In [1]: import dis In [2]: dis.dis(lambda: True == True != False) 1 0 LOAD_CONST 1 (True) 3 LOAD_CONST 1 (True) 6 DUP_TOP 7 ROT_THREE 8 COMPARE_OP 2 (==) 11 JUMP_IF_FALSE_OR_POP 21 14 LOAD_CONST 2 (False) 17 COMPARE_OP 3 (!=) 20 RETURN_VALUE >> 21 ROT_TWO 22 POP_TOP 23 RETURN_VALUE
If you read in bytecode, you can understand that it is executing a chain of statements.
Given that the expression True == True != False , which is "interpreted" as True == True and True != False , it first loads two True constants for the first statement through the LOAD_CONST . DUP_TOP duplicates the top of the stack (this avoids re-evaluating True for the second comparison). It performs the first comparison ( COMPARE_OP ) if it is false only for bytecode 21, otherwise it JUMP_IF_FALSE_OR_POP top of the stack ( JUMP_IF_FALSE_OR_POP ). He then performs a second comparison.
To answer your general question, the quickest way to find out about a python function is to use the quicksearch page in the documentation. I also suggest reading a Python tutorial for a general introduction to the language.
I would like to add that since python provides an interactive environment, it is often easier to understand how any code works by writing it in the interpreter and observing the results. Almost all buil-in types have documentation available through docstrings, so help(some_object) should provide you a lot of information. In particular, IPython provides an improved interactive interpreter with more convenient help messages / error formatting, etc.)
source share