What is more ‘pythonic’ for ‘not’ [duplicate]

The second option is more Pythonic for two reasons:

  • It is one operator, translating to one bytecode operand. The other line is really not (4 in a); two operators.

    As it happens, Python optimizes the latter case and translates not (x in y) into x not in y anyway, but that is an implementation detail of the CPython compiler.

  • It is close to how you’d use the same logic in the English language.

Leave a Comment