Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
SUPER() in Python explained! ๐Ÿ”ด
Play lesson

Python tutorial for beginners ๐Ÿ - SUPER() in Python explained! ๐Ÿ”ด

4.0 (0)
8 learners

What you'll learn

This course includes

  • 14.3 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

# 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()

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere