Phase 02 · Python FoundationsLesson 6 of 8
Object-Oriented Programming
Classes, objects, inheritance and the four pillars of OOP.
The problem
As programs grow, keeping data and the code that works on that data in separate places becomes messy. Object-Oriented Programming (OOP) bundles them together. A BankAccount knows its own balance and how to deposit and withdraw. Almost every serious Python library, including the AI agent frameworks later in this roadmap, is built with classes, so OOP is essential reading.
The concept
Deep dive: 4h 48m video. You don’t need it all in one sitting. Use the chapter list under the video to jump straight to the part you need.
Jump to a chapter 29 chapters
- 0:00:00Intro
- 0:03:20Intro to Functional Programming
- 0:07:12Why OOPS
- 0:16:11Component of OOPS
- 0:22:13Intro to Class and Object
- 0:33:40Constructor
- 0:40:04Self Keyword
- 0:49:56Creating Properties/Data Members
- 1:01:34Creating methods
- 1:10:30Complex Number Class Code
- 1:23:20__str__ method
- 1:33:20__add__ method
- 1:43:40__mul__ method
- 1:47:46__truediv__ method
- 1:53:30__eq__ method
- 1:59:32Instance variable
- 2:00:27Static Property
- 2:09:31Encapsulation in OOPS
- 2:13:15Access Modifier in Python
- 2:26:04Static property
- 2:38:11Inheritance in OOPS
- 2:57:00super() keyword
- 3:09:00Types Of Inheriatance
- 3:29:31Questions on Inheritance
- 3:39:00Polymorphism in OOPS
- 3:56:14Abstraction In OOPS
- 3:57:47Inheritance Question Again :(
- 4:25:51Abstraction Continued
- 4:45:33Outro and Please subscribe :)
Chapters from the video description on YouTube.
Classes and objects#
A class is a blueprint. An object (or instance) is a real thing built from that blueprint.
class BankAccount:
def __init__(self, owner, balance=0):
self.owner = owner # attribute
self.balance = balance # attribute
def deposit(self, amount): # method
self.balance += amount
return self.balance
acct = BankAccount("Ada", 100) # create an object
acct.deposit(50) # 150
print(acct.owner) # Ada
__init__runs automatically when an object is created and sets its starting attributes.selfis the object itself. Inside a method,self.balancemeans "this account's balance".- Functions defined inside a class are called methods.
Encapsulation: protect your data#
Methods control how data can change, so rules live in one place:
def withdraw(self, amount):
if amount > self.balance:
raise ValueError("Insufficient funds")
self.balance -= amount
Now nobody can accidentally drive the balance below zero, because the class enforces the rule.
Inheritance: reuse and extend#
A child class inherits everything from a parent class and can add or change behaviour:
class SavingsAccount(BankAccount):
def __init__(self, owner, balance=0, rate=0.04):
super().__init__(owner, balance) # reuse the parent's setup
self.rate = rate
def add_interest(self):
self.balance += self.balance * self.rate
s = SavingsAccount("Ravi", 1000)
s.deposit(500) # inherited from BankAccount
s.add_interest() # new behaviour
Parent and child class
BankAccountparent: owner, balance, deposit(), withdraw()
SavingsAccountchild: inherits everything fromBankAccount- Reuses the parent's setup
super().__init__(owner, balance) - Adds new behaviour
rateandadd_interest()
- Reuses the parent's setup
The four pillars#
| Pillar | In one line |
|---|---|
| Encapsulation | Keep data and the methods that change it together, behind clear rules |
| Abstraction | Expose what an object does, hide how it does it |
| Inheritance | Build new classes on top of existing ones |
| Polymorphism | Different classes respond to the same method call in their own way |
Why this matters for AI work#
In frameworks such as Google ADK and Microsoft AutoGen, agents, tools and model clients are objects. You'll create instances, configure their attributes and sometimes subclass them to customise behaviour. Being fluent with classes makes those frameworks feel familiar instead of magical.
Try it
Your task · about 10 minutes
Create a BankAccount class with deposit and withdraw methods that refuse to go below zero. Then make SavingsAccount inherit from it and add interest.
Recap & next
Key takeaways
- A class is a blueprint; an object is an instance created from it.
__init__runs when an object is created and sets its attributes;selfrefers to that object.- Inheritance lets a child class reuse and extend a parent class.
- The four pillars: encapsulation, abstraction, inheritance and polymorphism.
- Frameworks like AutoGen and ADK are class-based, so OOP is essential for agent work.
Quick check
2 questions · instant feedback
Go deeper
Finished this lesson?
Mark it complete to track your progress and keep your streak going.


