r/Python • • Jun 23 '14

Writing better python code

https://gist.github.com/kracekumar/09a60ec75a4de19b346e
143 Upvotes

126 comments sorted by

View all comments

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:

if a == None:

when they should be doing:

if a is None:

0

u/pymag09 Jun 23 '14 edited Jun 23 '14

I think
if 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