For the following two code:
if a and b:
then do something
if a:
if b:
then do something
What is the difference between these two statements in terms of semantics and the time it takes to execute? Do not both of them always evaluate the same? And is one of them faster than the other (I am not asking asymptotically, not the big O notation)?
Byte code with and:
7 0 LOAD_GLOBAL 0 (a)
2 POP_JUMP_IF_FALSE 8
4 LOAD_GLOBAL 1 (b)
6 POP_JUMP_IF_FALSE 8
8 >> 8 LOAD_CONST 0 (None)
10 RETURN_VALUE
Nested statement:
10 0 LOAD_GLOBAL 0 (a)
2 POP_JUMP_IF_FALSE 8
11 4 LOAD_GLOBAL 1 (b)
6 POP_JUMP_IF_FALSE 8
12 >> 8 LOAD_CONST 0 (None)
10 RETURN_VALUE
Edit: If I'm not making a mistake, they are generating exactly the same bytecode.