I'm pretty new to OOP and I need some help understanding the need for a constructor in a python class.
I understand init is used to initialize class variables like below:
class myClass():
def __init__ (self):
self.x = 3
print("object created")
A = myClass()
print(A.x)
A.x = 6
print(A.x)
Output:
object created
3
6
but, I could also just do,
class myClass():
x = 3
print("object created")
A = myClass()
print(A.x)
A.x = 6
print(A.x)
which prints out the same result.
Could you please explain why we need a constructor or give me an example of a case when the above method will not work?