Calling Foo(10) creates an object before __init__ assigns its attributes. The method responsible for creating and returning that instance is __new__, not __init__. section 9.5
Object creation proceeds in this order:
- Python resolves Foo as a class and calls it with 10. section 9.5
- __new__ creates a new Foo instance. section 9.5
- __new__ invokes __init__ before the instance is returned. section 9.5
- __init__ adds attributes such as self.x to the instance. section 9.5
Ordinary instance construction
class Foo: def __init__(self, x): self.x = x f = Foo(10) print(f.x) The usual pattern is to define __init__ and leave __new__ alone; redefining __new__ is rarely necessary. section 9.5


