In <66a3f64c-d35e-40c7-be69-ddf708e37...@glegroupsg2000goo.googlegroups.com> 
Niklas Rosencrantz <nikla...@gmail.com> writes:

> What's the story of using these parameters that are called "self"?

"self" is a reference to the class object, and it allows the method to
access other methods and variables within the class.

For example, say you have this class:

  class MyClass(object):

    def method1(self, x):
      self.x = x
      self.say_hello()

    def say_hello(self):
      self.x = self.x + 1
      print "hello"

Without the "self" reference, method1 wouldn't be able to access
instance variable x and it wouldn't be able to call say_hello().

If you have a method that doesn't need to access other variables or
methods within the class, you can declare it with the @staticmethod
decorator.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gor...@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to