The __new__ () creates a new instance.
The __init__ () method initializes that instance.
The __new__ method is a special method that is called before the __init__ method. It is responsible for creating the object and returning it.
The __new__ method is a class level method, which means that it is called on the class, rather than on an instance of the class.
The default implementation of __new__ is sufficient, no need to override it.
for example, to create a singleton class, we can use it to create only one instance.
The above code overrides the __new__ method to make sure there is only one instance. So, s1 == s2 statement is True.
Comments