week 3
Week 3: Object-Oriented Programming & Monkey Patching
1. Classes, Objects, and Constructors
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def greet(self):
return f"Hello, my name is {self.name} and I am {self.age} years old."
p1 = Person("Alice", 25)
print(p1.greet())class Car:
def __init__(self, brand="Toyota"):
self.brand = brand
c1 = Car()
print(c1.brand) # Output: Toyota2. Inheritance, Polymorphism, Encapsulation
3. Magic Methods (__str__, __repr__, __call__)
__str__, __repr__, __call__)4. Monkey Patching
5. More Advanced OOP Concepts
Last updated