Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # super() = FUNCTION USED TO GIVE ACCESS TO THE METHODS OF A PARENT CLASS.
- # RETURNS A TEMPORARY OBJECT OF A PARENT CLASS WHEN USED
- #---------------------------------------------------------
- class Rectangle:
- def __init__(self, length, width):
- self.length = length
- self.width = width
- #----------------------------------------------------------
- class Square(Rectangle):
- def __init__(self, length, width):
- super().__init__(length, width)
- def area(self):
- return self.length*self.width
- # self.length = length
- # self.width = width
- #--------------------------------------
- class Cube(Rectangle):
- def __init__(self, length, width, height):
- super().__init__(length, width)
- self.height = height
- def volume(self):
- return self.length*self.width*self.height
- # self.length = length
- # self.width = width
- square = Square(3, 3)
- cube = Cube(3, 3, 3)
- print(square.area())
- print(cube.volume())
- #----------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement