Initializing field outside __init__
问题 I need a bit of help to understand how python initialising works. I have a class (Bar) with another class (Foo) as a field/variable. When I try to initialise this variable directly in Bar (not in the class __init__) all instances of Bar will point to the same Foo. But if I have an __init__ method, as in Bar2, each Bar2 instance will have a unique Foo instance. What is happening here? class Foo(): number = 0 class Bar(): foo = Foo() class Bar2(): foo = None def __init__(self): self.foo = Foo()