Sunday 12 April 2015

Python 'self'

"The reason you need to use self. is because Python does not use the @ syntax to refer to instance attributes. Python decided to do methods in a way that makes the instance to which the method belongs be passed automatically, but not received automatically: the first parameter of methods is the instance the method is called on. That makes methods entirely the same as functions, and leaves the actual name to use up to you (although self is the convention, and people will generally frown at you when you use something else.) self is not special to the code, it's just another object."

"Because explicit is better than implicit."


source: http://stackoverflow.com/questions/2709821/what-is-the-purpose-of-self-in-python

No comments:

Post a Comment