When you define the class simply like this class Complex
you don't inherit the class from any other class and hence it only has those attributes which you define like __init__
(and __doc__
and __module__
.) This is a an old-style class.
When you define a class like this - class Complex(object)
, it means you inherit the class from the class object
. As a result, many of its attributes are inherited automatically without the need to yourself define them again like __str__
, __class__
, etc. This is new style class.
In python 2.x, new style classes are usually preferred as using old style classes may lead to some problems. For example, __slots__
, super
, descriptors
don't work in old style classes.
Old style classes have been kept in python 2.x just to maintain a backward compatibility. In python 3, this is cleaned up and any class you define is a new style class.
(Also, from what you say, inheriting from object
has nothing to do with only defining __init__
.)