+ 9
Why do we use self attribute in defining an instance of class? What is it's specific purpose?
Eg. class Cat: def __init__(self, color, legs): self.color = color self.legs = legs
4 Respostas
+ 12
Self is an object reference to the object itself. It is similar to this keyword of other programming languages.
Plz refer to this link :
https://stackoverflow.com/questions/2709821/what-is-the-purpose-of-self
+ 8
You can use any valid variable name, it's just that self is convention. It is an instance of a class i.e object reference to itself.
+ 1
#Meta
+ 1
It is the constructor in Python, strongly private with two underscores at the beginning.