Войти
  • 43544Просмотров
  • 1 год назадОпубликованоBro Code

SUPER() in Python explained! 🔴

# super() = Function used in a child class to call methods from a parent class (superclass). # Allows you to extend the functionality of the inherited methods class Shape: def __init__(self, color, is_filled): = color = is_filled def describe(self): print(f"It is { } and {'filled' if else 'not filled'}") class Circle(Shape): def __init__(self, color, is_filled, radius): super().__init__(color, is_filled) = radius def describe(self): print(f"It is a circle with an area of { * * }cm^2") super().describe() class Square(Shape): def __init__(self, color, is_filled, width): super().__init__(color, is_filled) = width def describe(self): print(f"It is a square with an area of { * }cm^2") super().describe() class Triangle(Shape): def __init__(self, color, is_filled, width, height): super().__init__(color, is_filled) = width = height def describe(self): print(f"It is a triangle with an area of { * / 2}cm^2") super().describe() circle = Circle(color="red", is_filled=True, radius=5) square = Square(color="blue", is_filled=False, width=6) triangle = Triangle(color="yellow", is_filled=True, width=7, height=8) () () ()