Object Oriented Programming
Model the real world as objects that bundle data with behavior. It is the most widely used programming paradigm in existence, and also the source of heated debates that have never been resolved and never will be.
class Animal:
def __init__(self, name):
self._name = name # encapsulated
def speak(self): # abstract
raise NotImplementedError
def name(self): # property
return self._name
class Dog(Animal): # inherits
def speak(self): # overrides
return "Woof!"
class Cat(Animal):
def speak(self): # polymorphic
return "Meow!"
# Dog().speak() → "Woof!"
Classes & Objects
6 min read • ReferenceData and methods. Explore complete syntax, detailed definitions, and structured coding examples.
Inheritance
6 min read • ReferenceCode reuse. Explore complete syntax, detailed definitions, and structured coding examples.
Polymorphism
6 min read • ReferenceDynamic dispatch. Explore complete syntax, detailed definitions, and structured coding examples.