From Full Stack to AI: Object Oriented Programming in Python
Learn Python's Object Oriented Programming for Full Stack and AI Development

I’m a full-stack developer who enjoys building practical, scalable applications with React.js, Node.js, and Next.js. My journey into open source started with Hacktoberfest 2023, and it opened the door to real collaboration, learning from global contributors, and supporting early developers as they grow.
Since then, I’ve contributed to and mentored in programs like GSSoC’24, SSOC’24, and C4GT’24. As a Google Gen AI Exchange Hackathon ’24 Finalist and a Google Women Techmakers Ambassador, I’ve had the chance to help communities explore AI and build meaningful solutions. I’m also part of the Top 1% mentors on Topmate, where I guide students on open source, career building, and technical growth.
My work has been featured at Times Square NYC, and I’ve spoken on international podcasts about tech, learning, and community. I’ve also written technical content for CoderArmy and continue to share insights through articles and public posts. LinkedIn has recognized my work with seven Top Voice badges as well as Golden Badges in research, critical thinking, teamwork, and interpersonal skills.
I completed my MCA from Chandigarh University in 2023 and continue to stay curious by exploring AI, building new projects, and contributing to developer communities. Whether it’s improving a UI, debugging backend logic, or helping someone with their first pull request, I enjoy learning alongside others.
If you want to collaborate, learn together, or discuss an idea, feel free to reach out at kumaripayal7488@gmail.com
Introduction
If you are coming from a full stack background and moving toward AI or machine learning, Python quickly becomes your main tool. Most AI libraries are written using Object Oriented Programming. If OOP feels confusing, learning AI will feel harder than it needs to be. This article is a simple walk through of core OOP ideas in Python using small examples and plain language. Think of it as personal learning notes shared openly.
1. Building Your First Class and Object
What is a class
A class is a blueprint. It tells Python how to create something.
What is an object
An object is a real thing created from that blueprint.
Code example
class Chai:
pass
class ChaiTime:
pass
print(type(Chai))
ginger_tea = Chai()
print(type(ginger_tea))
print(type(ginger_tea) is Chai)
print(type(ginger_tea) is ChaiTime)
Output
<class 'type'>
<class '__main__.Chai'>
True
False
Explanation
Chaiitself is a class and its type istypeginger_teais an object created fromChaiPython confirms that
ginger_teabelongs toChai, notChaiTime
2. Class and Namespace
What is a namespace
A namespace is like a storage area where variables live. Classes have their own namespace.
Code example
class Chai:
origin = "India"
print(Chai.origin)
Chai.is_hot = True
print(Chai.is_hot)
masala = Chai
print(f"Masala {masala.origin}")
print(f"Masala {masala.is_hot}")
masala.is_hot = False
print("Class:", Chai.is_hot)
print(f"Masala {masala.is_hot}")
Output
India
True
Masala India
Masala True
Class: False
Masala False
Explanation
originlives inside the classYou can add new attributes like
is_hotdynamicallymasalapoints to the same class, not a new objectChanging it affects the class itself
3. Attribute Shadowing
What is attribute shadowing
When an object creates its own attribute with the same name as the class attribute, it hides the class one.
Code example
class Chai:
temperature = "hot"
strength = "Strong"
cutting = Chai()
print(cutting.temperature)
cutting.temperature = "Mild"
cutting.cup = "small"
print("After changing", cutting.temperature)
print("cup size is", cutting.cup)
print("Direct look into the class", Chai.temperature)
del cutting.temperature
del cutting.cup
print(cutting.temperature)
print(cutting.cup)
Output
hot
After changing Mild
cup size is small
Direct look into the class hot
hot
AttributeError
Explanation
Initially the object reads from the class
Once you assign
cutting.temperature, the object gets its own copyDeleting it reveals the class value again
cupnever existed on the class, so deleting it fully removes it
4. The self Argument
What is self
self is how an object refers to itself inside a class.
Code example
class Chaicup:
size = 150
def describe(self):
return f"A {self.size}ml chai cup"
cup = Chaicup()
print(cup.describe())
print(Chaicup.describe(cup))
cup_two = Chaicup()
cup_two.size = 100
print(Chaicup.describe(cup_two))
Output
A 150ml chai cup
A 150ml chai cup
A 100ml chai cup
Explanation
cup.describe()is just a cleaner way to callChaicup.describe(cup)selfreceives the object automaticallyEach object can have its own values
5. Constructors and __init__
What is a constructor
A constructor runs when an object is created. It prepares the object.
Code example
class ChaiOrder:
def __init__(self, type_, size):
self.type = type_
self.size = size
def summary(self):
return f"{self.size}ml of {self.type} chai"
order = ChaiOrder("Masala", 200)
print(order.summary())
order_two = ChaiOrder("Ginger", 220)
print(order_two.summary())
Output
200ml of Masala chai
220ml of Ginger chai
Explanation
__init__assigns values at creation timeEvery object gets its own data
This pattern is everywhere in real projects
6. Inheritance and Composition
Inheritance
One class builds on another.
Composition
One class uses another class.
Code example
class BaseChai:
def __init__(self, type_):
self.type = type_
def prepare(self):
print(f"Preparing {self.type} chai")
class MasalaChai(BaseChai):
def add_spices(self):
print("Adding cardamom, ginger, cloves")
class ChaiShop:
chai_cls = BaseChai
def __init__(self):
self.chai = self.chai_cls("Regular")
def serve(self):
print(f"Serving {self.chai.type} chai")
self.chai.prepare()
class FancyChaiShop(ChaiShop):
chai_cls = MasalaChai
shop = ChaiShop()
fancy = FancyChaiShop()
shop.serve()
fancy.serve()
fancy.chai.add_spices()
Output
Serving Regular chai
Preparing Regular chai
Serving Regular chai
Preparing Regular chai
Adding cardamom, ginger, cloves
Explanation
MasalaChaiinherits behavior fromBaseChaiChaiShopuses another class internallyThis pattern is common in scalable systems
7. Three Ways to Access a Base Class
Code example
class Chai:
def __init__(self, type_, strength):
self.type = type_
self.strength = strength
print(f"Chai created | Type: {self.type}, Strength: {self.strength}")
class GingerChai(Chai):
def __init__(self, type_, strength, spice_level):
super().__init__(type_, strength)
self.spice_level = spice_level
print(
f"GingerChai created | Type: {self.type}, "
f"Strength: {self.strength}, Spice Level: {self.spice_level}"
)
chai = GingerChai("Ginger", "Strong", "High")
Output
Chai created | Type: Ginger, Strength: Strong
GingerChai created | Type: Ginger, Strength: Strong, Spice Level: High
Explanation
super()is the cleanest wayIt avoids code duplication
It works well with multiple inheritance
8. Method Resolution Order (MRO)
What is MRO
MRO decides which class Python checks first when looking for a method or attribute.
Code example
class A:
label = "A: Base class"
class B(A):
label = "B: Masala blend"
class C(A):
label = "C: Herbal blend"
class D(B, C):
pass
cup = D()
print(cup.label)
print(D.__mro__)
Output
B: Masala blend
(<class 'D'>, <class 'B'>, <class 'C'>, <class 'A'>, <class 'object'>)
Explanation
Python checks from left to right
Understanding MRO avoids strange bugs in large systems
9. Static Methods
What is a static method
A static method belongs to a class but does not use class or object data.
Code example
class ChaiUtils:
@staticmethod
def clean_ingrediants(text):
return [item.strip() for item in text.split(",")]
raw = "water , milk , honey "
cleaned = ChaiUtils.clean_ingrediants(raw)
print(cleaned)
Output
['water', 'milk', 'honey']
Explanation
No
selfNo
clsUseful for helper logic related to the class
10. Classmethod vs Staticmethod
Code example
class ChaiOrder:
def __init__(self, tea_type, sweetness, size):
self.tea_type = tea_type
self.sweetness = sweetness
self.size = size
@classmethod
def from_dict(cls, order_data):
return cls(
order_data["tea_type"],
order_data["sweetness"],
order_data["size"],
)
@classmethod
def from_string(cls, order_string):
tea_type, sweetness, size = order_string.split("-")
return cls(tea_type, sweetness, size)
class ChaiUtils:
@staticmethod
def is_valid_size(size):
return size in ["Small", "Medium", "Large"]
print(ChaiUtils.is_valid_size("Medium"))
order1 = ChaiOrder.from_dict({"tea_type": "masala", "sweetness": "medium", "size": "Large"})
order2 = ChaiOrder.from_string("Ginger-Low-Small")
order3 = ChaiOrder("Large", "Low", "Large")
print(order1.__dict__)
print(order2.__dict__)
print(order3.__dict__)
Explanation
classmethodcreates objects in different waysstaticmethodvalidates or transforms dataBoth are common in real APIs
11. Property Decorator
What is a property
It lets you control how attributes are read and written.
Code example
class TeaLeaf:
def __init__(self, age):
self._age = age
@property
def age(self):
return self._age + 2
@age.setter
def age(self, age):
if 1 <= age <= 5:
self._age = age
else:
raise ValueError("Tea Leaf age must be between 1 and 5 years")
leaf = TeaLeaf(2)
print(leaf.age)
leaf.age = 4
print(leaf.age)
Output
4
6
Explanation
You protect internal data
You add logic without changing how users access it
This is widely used in clean Python design
Closing Thoughts
If OOP feels long or repetitive, that is normal. Strong foundations matter more than speed when moving into AI. Most frameworks assume you understand classes, objects, inheritance, and method behavior. Learn step by step, write small experiments, and keep revisiting the basics. Over time, these concepts start to feel natural.





