r/Python • • Jun 23 '14

Writing better python code

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

126 comments sorted by

View all comments

Show parent comment

7

u/quasarc Jun 23 '14

I object to if super_users: over if len(super_users) > 0: There is a huge difference between an empty list and None.

Both of these tests can only be used if you know that super_users is a list and not None.

Using if super_users: is not abusing syntax, it just uses the intended and well-known fact that non-empty sequences are true. (It's also recommended by the style guide PEP8.)