Section 1/5Procedural vs Object-Oriented
Procedural vs Object-Oriented
In procedural code you track a car like this:
What is Object-Oriented Programming?
Before OOP, programs were written in a procedural style — a list of instructions operating on separate variables. OOP changes this by bundling related data and behaviour together into objects.
Procedural vs Object-Oriented
In procedural code you track a car like this:
car_brand = "Toyota"
car_speed = 0
car_colour = "red"
# Three unrelated variables for one carWith OOP you create a Car class and each car is one object:
class Car:
def __init__(self, brand, colour):
self.brand = brand
self.colour = colour
self.speed = 0
my_car = Car("Toyota", "red")→
All data lives inside my_car