[Tutor] Why is the name "self" optional instead of mandatory?

Steven D'Aprano steve at pearwood.info
Fri Jan 29 22:35:21 EST 2016


On Fri, Jan 22, 2016 at 11:10:39PM -0600, boB Stepp wrote:

> Am I understanding this correctly?  It appears to me that you have
> successfully added a method to class X from outside of class X!  If
> this is the case, then this clarifies some things I was wondering
> about in my other thread.


If you are looking for a real-world example of why you might add a 
method to an instance, please look at the thread started by Ryan:

"Why define a function inside a function?"


for an example of adding a pseudo-method to a specific instance (not the 
entire class).

For technical reasons, it's not actually a method, it's a regular 
function, but the difference is not important.


-- 
Steve


More information about the Tutor mailing list