[Tutor] methods and functions

Lloyd Kvam pythontutor@venix.com
Fri Jun 13 11:57:02 2003


I'm with you.  A method is a function.  The differences lie
in how each is found, and of course the first parameter
is grabbed from "before the dot".  mymodule.myfunc(obj) is found by
searching the mymodule namespace.  obj.myfunc() is found by searching
the class parentage of obj.  For many common cases the function
source code would look the same.  The method code becomes visibly different
when it depends upon special class features.  So a method has a richer environment
to operate in.  A method is essentially a function defined within a class body.

Danny wrote (6/12/03 5:02 PM PDT) an example for converting a function
into a method, so clearly methods and functions are not terribly different.

http://aspn.activestate.com/ASPN/Mail/Message/python-Tutor/1670425
ASPN : Mailing List Archive

Alex Martelli's "Python in a Nutshell" is lucid and brief.  My kids have my
Wesley Chung and Tom Christopher books, but I would expect reasonable explanations
in both.  Alan Gauld's web site is also helpful.
http://www.freenetpages.co.uk/hp/alan.gauld/
Learning to program

Gerardo Arnaez wrote:
 > well, a few nights a go, I had a eureka moment.
 > I finally grokked what __init__ and self really meant.
 >
 > Let me tell ya', from everything I had read it was
 > never really obvious, until I started thinking of self
 > as just another parameter.
 >
 > anyway, I had a discussion about it on irc.debian.org
 > #python and was surprised to learn that thinking
 > methods were the same thing as functions.  I was told
 > this was not the case, but every example I was given.
 > it looked to me that when a method was called for an
 > instance, it just like calling a function.
 >
 > What is the difference?
 > where can I read to understand this point?
 >
 > __________________________________
 > Do you Yahoo!?
 > Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
 > http://calendar.yahoo.com
 >
 > _______________________________________________
 > Tutor maillist  -  Tutor@python.org
 > http://mail.python.org/mailman/listinfo/tutor
 >


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-443-6155
fax:	801-459-9582