__init__ method returns a value¶
__init__ method of a class is used to initialize new objects, not create them. As such, it should not return any value. Returning
None is correct in the sense that no runtime error will occur, but it suggests that the returned value is meaningful, which it is not.
return expr statement to a plain
return statement, or omit it altogether if it is at the end of the method.
In this example, the
__init__ method attempts to return the newly created object. This is an error and the return method should be removed.
def __init__(self, i):
self.i = i
Python: The init method.