Learn Python Object Oriented Programming! 🚗

Veröffentlicht am: 20 Mai 2024
auf dem Kanal: Bro Code
23,885
810

#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()

--------------------------------------


Auf dieser Seite können Sie das Online-Video Learn Python Object Oriented Programming! 🚗 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Bro Code 20 Mai 2024 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 23,885 Mal angesehen und es wurde von 810 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!