Python Object Oriented Programming!🐍

Поділитися
Вставка
  • Опубліковано 21 січ 2025

КОМЕНТАРІ • 2

  • @YousefCompSci
    @YousefCompSci  3 місяці тому +1

    # POOP = Python object-oriented programming
    # Each object can have its own set of methods and attributes
    from car import Car
    car1 = Car("Chevy", "Corvette", 2019, "Black")
    car2 = Car("Chevy", "Camaro", 2014, "Red")
    car3 = Car("Wooden", "sofa", 2020, "purple")
    print(car3.make)
    print(car3.model)
    print(car3.year)
    print(car3.color)
    car3.drift()
    car3.drive()
    car2.wheels = 2
    print(car3.wheels)
    class Car:
    wheels = 4 # class variable
    def __init__(self, make, model, year, color):
    self.make = make # instance variables
    self.model = model # instance variables
    self.year = year # instance variables
    self.color = color # instance variables
    def drift(self):
    print("This "+self.model+" is drifting :D")
    def drive(self):
    print("This "+self.model+" is driving :D")
    class motorcycle:
    pass

  • @Monsta1291
    @Monsta1291 3 місяці тому