SUPER() in Python explained! 🔴

Published: 24 May 2024
on channel: Bro Code
10,000
359

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):
self.color = color
self.is_filled = is_filled

def describe(self):
print(f"It is {self.color} and {'filled' if self.is_filled else 'not filled'}")

class Circle(Shape):
def __init__(self, color, is_filled, radius):
super().__init__(color, is_filled)
self.radius = radius

def describe(self):
print(f"It is a circle with an area of {3.14 * self.radius * self.radius}cm^2")
super().describe()

class Square(Shape):
def __init__(self, color, is_filled, width):
super().__init__(color, is_filled)
self.width = width

def describe(self):
print(f"It is a square with an area of {self.width * self.width}cm^2")
super().describe()

class Triangle(Shape):
def __init__(self, color, is_filled, width, height):
super().__init__(color, is_filled)
self.width = width
self.height = height

def describe(self):
print(f"It is a triangle with an area of {self.width * self.height / 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)

circle.describe()
square.describe()
triangle.describe()


Watch video SUPER() in Python explained! 🔴 online without registration, duration hours minute second in high quality. This video was added by user Bro Code 24 May 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 10,00 once and liked it 35 people.