Which is more preferred below? and why?
Does PEP8 have a say in this?
if retcode != 0 and not "ignore_warning" in cmd_out:
or
if retcode != 0 and "ignore_warning" not in cmd_out:
functionally, i believe they achieve the same
Use "is not" operator rather than "not ... is" . While both expressions are functionally identical, the former is more readable and preferred.
Looking at the disassembled bytecode both the expressions are the same. From readability point of view second option is better.
if a != 10 and not b in "test":
and
if a != 10 and b not in "test":
gives the same disassembled code
2 0 LOAD_FAST 0 (a)
2 LOAD_CONST 1 (10)
4 COMPARE_OP 3 (!=)
6 POP_JUMP_IF_FALSE 26
8 LOAD_FAST 1 (b)
10 LOAD_CONST 2 ('test')
12 COMPARE_OP 7 (not in)
14 POP_JUMP_IF_FALSE 26