Everything up to this point has been procedural — a script running top to bottom. Object-oriented programming (OOP) groups related data and behavior together into a single unit called an object, with Python's own syntax for it.
A class is a blueprint; an object is one actual instance built from it — same relationship as an architectural plan and an actual house built from it.
class Student:
def __init__(self, name, course):
self.name = name
self.course = course
def introduce(self):
return f"Hi, I'm {self.name}, studying {self.course}."
student1 = Student("Priya", "Web Development")
print(student1.introduce()) # "Hi, I'm Priya, studying Web Development."__init__ is Python's constructor — it runs automatically when Student(...) is called. self refers to "this particular object" — Python makes it an explicit first parameter on every method, rather than something implicitly available the way some other languages handle it.
student2 = Student("Amit", "Graphic Design")
print(student1.name) # still "Priya" — unaffected by student2
print(student2.name) # "Amit"Python uses a plain dot for both properties and methods — there's only one access syntax to remember, not a different one for objects vs. everything else:
print(student1.name) # property access
print(student1.introduce()) # method callEverything so far — self.name, self.course — is an instance variable: its own separate copy per object. A class variable, defined directly inside the class body instead of inside __init__, is shared by every instance:
class Student:
school = "Learn Computer Academy" # class variable — one copy, shared by all
def __init__(self, name):
self.name = name # instance variable — separate per object
s1 = Student("Priya")
s2 = Student("Amit")
print(s1.school, s2.school) # both "Learn Computer Academy" — same shared valueUse a class variable for something genuinely shared by every instance (a constant, a shared counter) and an instance variable for anything that varies per object — which, in practice, is most of what a class holds.
More is coming immediately
The next lesson builds directly on this one, covering inheritance (one class building on another) and polymorphism (different classes responding to the same method call in their own way).