Main.NewClasses History

Hide minor edits - Show changes to markup

April 08, 2010, at 09:41 PM MST by 71.196.160.210 -
Added lines 1-32:

(:source lang=python:)

""" New style classes """

class Point :

    """Point is a class that stores a two dimensional point"""
    def __init__(self, x=0, y=0) :
        self.x = x
        self.y = y
    def __repr__(self) :
        return "Point object with x = d" % (self.x, self.y)

class Point2 (object) :

    """Point2 is a class that stores a two dimensional point"""
    def __init__(self, x=0, y=0) :
        self.x = x
        self.y = y
    def __repr__(self) :
        return "Point2 object with x = d" % (self.x, self.y)

p1 = Point(1, 2) p2 = Point2(4, 6)

print type(p1) print type(p2)

  1. Here's a link to a nice explanation of new vs old-style classes:
  2. http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes

(:sourceend:)