MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/28utww/writing_better_python_code/cietkoe/?context=3
r/Python • u/kracekumar • Jun 23 '14
126 comments sorted by
View all comments
12
The normal code "is" example seems strange. I think the non-pythonic thing most programmers do with respect to "is" is not using it, for example:
if a == None:
when they should be doing:
if a is None:
0 u/pymag09 Jun 23 '14 edited Jun 23 '14 I thinkif not a:is better 3 u/steve_no Jun 23 '14 if not a:will also be True when a is 0, '', [], {}, or a datetime.time of midnight
0
I thinkif not a:is better
if not a:
3 u/steve_no Jun 23 '14 if not a:will also be True when a is 0, '', [], {}, or a datetime.time of midnight
3
will also be True when a is 0, '', [], {}, or a datetime.time of midnight
12
u/steve_no Jun 23 '14
The normal code "is" example seems strange. I think the non-pythonic thing most programmers do with respect to "is" is not using it, for example:
when they should be doing: