In Python 2, there's 2 types of classes. To use the new-style, you have to inherit explicitly from object
. If not, the old-style implementation is used.
In Python 3, all classes extend object
implicitly, whether you say so yourself or not.
You probably will want to use the new-style class anyway but if you code is supposed to work with both python 2 and 3 you'll have to explicitly inherit from object:
class Foo(object):
pass
To jump on the other answer, yes the Zen of Python state that
Explicit is better than implicit.
I think this mean we should avoid possible confusion in code like we should in language in general, remember code is communication.
If you only work with python 3, and your code/project explicitly state that, there is no possible confusion, all class without explicit inheritance automatically inherit from object. If for some obscure reason the base class change in the future (let's imagine from object to Object), the same code will work. And the Zen of Python also says that
Simple is better than complex.
(of course complex is quite an overstatement in this example but still...)
So again if you code only support python3, you should use the simplest form:
class Foo:
pass
The form with just ()
is quite useless since it doesn't give any valuable information.