Python Object Oriented Programming in 10 minutes

8 Views
Published
python object oriented programming OOP tutorial example explained

#python #objects #OOP

#------------------------------------------------------------------
from car import Car

car_1 = Car("Chevy","Corvette",2021,"blue")
car_2 = Car("Ford","Mustang",2022,"red")

car_1.drive()
car_2.stop()
#------------------------------------------------------------------
class Car:

def __init__(self,make,model,year,color):
self.make = make
self.model = model
self.year = year
self.color = color

def drive(self):
print("This "+self.model+" is driving")

def stop(self):
print("This "+self.model+" is stopped")
#------------------------------------------------------------------

music credits
Category
Bro Code
Tags
python, python oop, python object oriented programming
Be the first to comment