Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

OOP – Polymorphism | Python Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Python Fundamentals

Lesson 27 of 55

·Python

OOP – Polymorphism

20 minutes

Course progress49%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • Different classes share a method name (e.g., `area`).
  • Code that uses the common method works with any subclass.
  • Enables flexible APIs and reduces conditionals.

OOP – Polymorphism

Polymorphism means “many forms”. Different classes can be used interchangeably if they implement the same interface or method signature.

class Shape:
    def area(self):
        raise NotImplementedError

class Square(Shape):
    def __init__(self, side):
        self.side = side
    def area(self):
        return self.side * self.side

class Circle(Shape):
    def __init__(self, radius):
        self.radius = radius
    def area(self):
        import math
        return math.pi * self.radius ** 2

shapes = [Square(3), Circle(2)]
for s in shapes:
    print('Area:', s.area())

Both Square and Circle implement area(), allowing the loop to treat them uniformly.

Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Python FundamentalsBrowse activities
Previous lessonOOP – InheritanceContinue to lesson 28OOP – EncapsulationBack to Python Fundamentals curriculum