It is not okay for a class to have an
__init__ with an empty body.
__init__ must do something
The body of __init__ can be empty
CorrectionHere is what's right.
The following class is perfectly valid, although not useful:
class Device: def __init__(self): pass
What happens when executing an empty
Despite the above
__init__ of class
Device being empty, the Python interpreter will simply call this method after instantiating the object. While having an empty
__init__ is useless, it is allowed in the language.
But doesn’t it have to return the object?
__init__ should not have an explicit return: although having a return statement in the
__init__ is valid, it is not meaningful. It is just a default method that gets invoked upon object instantiation, which is usually used to set up instance variables and other operations.