MENU

Fun & Interesting

Learn Python Object Oriented Programming! 🚗

Bro Code 48,285 11 months ago
Video Not Working? Fix It Now

#python #pythonprogramming #pythontutorial 00:00:00 introduction 00:01:53 classes 00:02:19 constructors 00:04:13 instantiate objects 00:05:06 attribute access operator 00:06:09 multiple objects 00:07:19 modules 00:08:21 methods 00:11:52 conclusion # object = A "bundle" of related attributes (variables) and methods (functions) # Ex. phone, cup, book # You need a "class" to create many objects # class = (blueprint) used to design the structure and layout of an object # --------------- car.py --------------- class Car: def __init__(self, model, year, color, for_sale): self.model = model self.year = year self.color = color self.for_sale = for_sale def drive(self): # print("You drive the car") # print(f"You drive the {self.model}") print(f"You drive the {self.color} {self.model}") def stop(self): # print("You stop the car") # print(f"You stop the {self.model}") print(f"You stop the {self.color} {self.model}") def describe(self): print(f"{self.year} {self.color} {self.model}") # -------------------------------------- # --------------- main.py --------------- from car import Car car1 = Car("Mustang", 2024, "red", False) car2 = Car("Corvette", 2025, "blue", True) car3 = Car("Charger", 2026, "yellow", True) print(car1.model) print(car1.year) print(car1.color) print(car1.for_sale) car1.drive() car1.stop() car3.describe() # --------------------------------------

Comment