View Single Post
Old Jun 4th, 2006, 11:14 AM   #3
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by bulio
Is it because self will make the object run what is inside of it? (And therefore use the print?)
I'm not quite sure what you mean here.

In Python, the first argument of a method belonging to a function is a reference to the object the function is contained within. This argument is, by convention, called "self".

Thus:
x = MyClass()
x.foobar()
Is the same as:
x = MyClass()
MyClass.foobar(x)
The "self" argument allows a method to access the object in which it is contained.

e.g.:
class Test:
    def __init__(self):
        self.x = 10
        self.y = 5

t = Test()
print t.x, t.y
Prints out:
10 5
Arevos is offline   Reply With Quote