This best practice is not without reason.
When testing if object:
you are basically calling the objects __bool__
method, which can be overridden and implemented according to object behavior.
For example, the __bool__
method on collections (__nonzero__
in Python 2) will return a boolean value based on whether the collection is empty or not.
(Reference: http://docs.python.org/reference/datamodel.html)