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)intox not in yanyway, 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.