Message218837
Python accepts both syntaxes:
if not item in some_list and not item is None:
return item
and
if item not in some_list and item is not None:
return item
In the first form, you identify 5 operators: "not", "in", "and", "not" and "in"
In the second form, you find only 3 operators: "not in", "and", "is not"
Of course CPython does internal optimization, and it compiles both expressions to the same bytecode.
However the second form is more readable and less error-prone. It is plain English.
I propose to add such advice to the section "Programming Recommendations" of PEP 8. |
|
Date |
User |
Action |
Args |
2014-05-20 05:59:44 | flox | set | recipients:
+ flox, barry, ncoghlan, docs@python |
2014-05-20 05:59:44 | flox | set | messageid: <1400565584.02.0.148226279911.issue21540@psf.upfronthosting.co.za> |
2014-05-20 05:59:43 | flox | link | issue21540 messages |
2014-05-20 05:59:42 | flox | create | |
|