Python Classroom notes 02/Apr/2026

Abstract Classes

  • To make a class abstract
from abc import ABC, abstractmethod

class MyBase(ABC):
    @abstractmethod
    def something(self,...):
        pass
  • If we dervie the base from ABC child objects creation will be failed if the contracts are not implemented
  • Refer Here for changes and Refer Here for notebook.

Overloading and Overriding

  • Overloading => Same method name with different arguments
  • Overriding => Child class changing parent method

  • Overriding

class Animal:
    def sound(self):
        print("....")

class Dog(Animal):
    # overriden
    def sound(self):
        print("bark")

  • Overloading

def add(a, b, c=0):
    return a + b + c

# def add(*args):
#    return sum(args)

# def add(**kwargs):
    ...

Duck Typing

  • In python
    • We dont care about the objects type
    • we care about what it can do (methods/behavior)
  • Refer Here for notebook with duck typing.

By continuous learner

enthusiastic technology learner

Leave a Reply

Discover more from Direct AI Powered By Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading