class Point:
def __init__(self, x = 0, y = 0):
self.x, self.y = x, y
print "New Point object", self, "constructed"
def __str__(self):
return "(" + str(self.x) + "," + str(self.y) + ")"
def __del__(self):
print "Destructor"
pt1 = Point()
Output:
New Point object (0,0) constructed
Method functions receive a special first argument, called self
by very strong convention, which is the instance object that is the implied subject of the method call, and gives access to instance attributes.
So why is self
in init() printing (0, 0)
instead of pt1
? Isn't pt1
the instance object?