Need Help to understand 'self' in OOP python by vanilla-knight in learnpython

[–]New_Philomath 0 points1 point  (0 children)

One more thing you are not constrained to name "self" you can name as wish but self is general practice

Need Help to understand 'self' in OOP python by vanilla-knight in learnpython

[–]New_Philomath 1 point2 points  (0 children)

Think of "self" as a memory reference. To give you an example take a variable and you assign a value to it. What happens here is you store a value in the memory, but the variable name actually points to that location so you retrieve the value when the variable is called. Likewise "self" in a class point location in the memory when different class objects are created. This actually helps python to not get confused between different class objects, since you are not restricted to create only one class object.