Notice: While JavaScript is not essential for this website, your interaction with the content will be limited. Please turn JavaScript on for the full experience.
...math >>> math.pi.__init__(3.0) >>> print math.pi 3.0 >>> I could have fixed this problem in other ways, for example by adding an "already initialized" flag or only allowing __init__ to be called on subclass instances, but those solutions are inelegant. Instead, I added __new__, which is a perfectly general mechanism that can be used by built-in and user-defined classes, for immutable and mutable objects. Here are some rules for __new__: __new__ is a static...
...math >>> math.pi.__init__(3.0) >>> print math.pi 3.0 >>> I could have fixed this problem in other ways, for example by adding an "already initialized" flag or only allowing __init__ to be called on subclass instances, but those solutions are inelegant. Instead, I added __new__, which is a perfectly general mechanism that can be used by built-in and user-defined classes, for immutable and mutable objects. Here are some rules for __new__: __new__ is a static method. When d...
If you didn't find what you need, try your search in the Python language documentation.