[Tutor] understanding classes

Lance E Sloan lsloan@umich.edu
Wed, 14 Aug 2002 10:42:56 -0400


--On Wednesday, August 14, 2002 3:07 PM +0100 alan.gauld@bt.com wrote:
>> I have one question:  As far as you know, is "self" in Python
>> basically the same as "this" in Java?
>
> Exactly so and if it helps you can even call it 'this':
>
> class Foo:
>    baz = "Class Foo"
>    def bar(this):
>      return this.baz

Thanks for the confirmation.  Gregor and others confirmed that for me, too, 
also pointing out that it's a keyword in Java, but an explicitly defined 
variable in Python.  Is there a special term to refer to that variable, 
like "instance variable"?

My next question was going to be, why is the Python convention to name that 
variable "self" rather than "this"?  I suspect it's just Guido's choice. 
Was Java not so well known when this was done?  Or is this an intentional 
choice to distance Python from Java?

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Python & Perl CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"