We can call methods of parenet class without initliaze it?

scruel tao scruelt at hotmail.com
Wed Mar 15 05:57:39 EDT 2023


The following code won’t be allowed in Java, but in python, it works fine:
```python
class A:
    A = 3

    def __init__(self):
        print(self.A)

    def p(self):
        print(self.A)
        self.A += 1


class B(A):
    def __init__(self):
        print(2)
        self.p()
        super().__init__()


B()
```

How can I understand this? Will it be a problem?


More information about the Python-list mailing list