Python Object Oriented Programming!🐍

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ก.ย. 2024
  • PLEASE LIKE AND SUBSCRIBE ITS FREE!
    #beginners #tutorial #python
    Check out my other videos to learn more computer science & programming concepts please :)
    Code used in the video will be pinned in the comments!
    Socials and other platforms:
    linktr.ee/Yous...

ความคิดเห็น • 2

  • @YousefCompSci
    @YousefCompSci  วันที่ผ่านมา +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 วันที่ผ่านมา