Python Tutorial · Revision notes

Python OOPs

Object-oriented programming models a program as objects that bundle data (attributes) and behaviour (methods). Python supports classes, constructors, inheritance, abstraction, encapsulation, access conventions, overloading-style techniques and polymorphism.

Quick revision

  • Four pillars: encapsulation, abstraction, inheritance, polymorphism.
  • __init__ initialises; one per class; use defaults and @classmethod factories.
  • super() follows the MRO; check with Class.__mro__.
  • ABC + @abstractmethod: cannot instantiate until all are implemented.
  • _x protected by convention; __x mangled to _Class__x.
  • No true method overloading: use defaults, *args, singledispatch.
  • Duck typing: if the method exists, it works.
Read the full Python OOPs notes on Doubtclip →