Simple questions about classes
Grant Edwards
grante at visi.com
Tue Feb 11 15:23:09 EST 2003
In article <bbb4a9e1.0302111148.48dc074b at posting.google.com>, Natan wrote:
> I think self points to the class,
No, self points to an instance of the class.
> but why do we need to pass this parameter to every function?
While you have to declare it, you don't have to pass it when
you're calling a bound method. You only have to pass it when
calling an unbound method:
class A:
def foo(self,arg):
print "foo:",`self`,arg
def bar(self,arg):
print "bar:",`self`,arg
a1 = A()
a2 = A()
a1.foo("asdf")
A.foo(a1,"asdf")
a2.foo("qwer")
A.foo(a2,"qwer")
a1.bar(3.14159)
A.bar(a1,42)
--
Grant Edwards grante Yow! .. Do you like
at "TENDER VITTLES?"?
visi.com
More information about the Python-list
mailing list