Oop in python
Python supports object-oriented programming with classes, inheritance, polymorphism, and encapsulation. The __init__ method initializes instances, self references the instance, and special methods (__str__, __repr__) customize behavior.
Example
class Animal:
def __init__(self, name: str):
self.name = name
def speak(self) -> str:
raise NotImplementedError
class Dog(Animal):
def speak(self) -> str:
return f"{self.name} says Woof!"Inheritance lets Dog extend Animal while implementing its own speak method.