Rectangle class : Class Definition « Class « Python Tutorial






class Rectangle:
    def __init__(self):
        self.width = 0
        self.height = 0
    def setSize(self, size):
        self.width, self.height = size
    def getSize(self):
        return self.width, self.height

r = Rectangle()
r.width = 10
r.height = 5
print r.getSize()
r.setSize((150, 100))
print r.width








11.9.Class Definition
11.9.1.Demonstrates a basic class and object
11.9.2.Creating a Class (Class Definition)
11.9.3.Classes and Types
11.9.4.Defining Class Methods with the def Statement
11.9.5.Rectangle class
11.9.6.Throwing Methods Around
11.9.7.Simple definition of class Time.
11.9.8.Definition of class Date.