What is the "self" name always referring to...?

Mark McEahern mark at mceahern.com
Wed Dec 10 07:48:30 EST 2003


On Wed, 2003-12-10 at 00:31, Todd Gardner wrote:
> Is there something special about the word "self" or did Mr. Guido van
> Rossum just decide to us the word arbitrarily?

Yes, there is something special about "self":  It's what most people use
when writing Python to refer to the current instance within a method of
a class.

You can spell "the current instance" however you want:

  class Foo:

    def __init__(iLikeToBeARebelWithoutACause):
      iLikeToBeARebelWithoutACause.bar = True

  f = Foo()
  print f.bar

But *should* you?  <wink>

Cheers,

// m






More information about the Python-list mailing list