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 — the same core idea as PHP's OOP, with Python's own syntax.
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, exactly like PHP's __construct(). self refers to "this particular object," equivalent to PHP's $this — the difference is Python makes it an explicit first parameter on every method, rather than something implicitly available.
student2 = Student("Amit", "Graphic Design")
print(student1.name) # still "Priya" — unaffected by student2
print(student2.name) # "Amit"Unlike PHP's -> arrow, 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 callMore 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).