Class
In [2]:
class Rectangle(object):
def __init__(self, w=0, h=0):
self.w=w
self.h=h
def get_area(self):
return self.w*self.h
def __str__(self):
return "w:{}, h:{}, area:{}".format(self.w, self.h, self.get_area())
In [4]:
rec = Rectangle()
print(rec)
In [6]:
rec = Rectangle(w=3,h=4)
print(rec)
In [7]:
class Square(Rectangle):
def __init__(self, e=0):
self.w=e
self.h=e
In [8]:
sq=Square(5)
print(sq)
In [ ]: