1+ # Python Object Oriented Programming
2+ # object = A "bundle" of related attributes and methods(functions)
3+ # Ex. phone, cup, book, car, dog
4+ # You need a "class" to create many objects of the same type
5+
6+ # class = (blueprint) used to design the structure and layout of an object
7+
8+ # method = A function that is defined inside a class
9+
10+ # DUNDER means double underscore __init__ = constructor method
11+
12+ # create a class
13+ class Car :
14+ # attributes
15+ def __init__ (self , make , model , year , color ): # constructor method
16+ self .make = make
17+ self .model = model
18+ self .year = year
19+ self .color = color
20+ self .mileage = 0
21+ self .for_sale = False
22+
23+ # define methods
24+ def drive (self ):
25+ print (f"The { self .make } is driving." )
26+
27+ def stop (self ):
28+ print (f"The { self .make } has stopped." )
29+
30+ def left_turn (self ):
31+ print (f"The { self .make } is turning left." )
32+ def right_turn (self ):
33+ print (f"The { self .make } is turning right." )
34+ def park (self ):
35+ print (f"The { self .make } is parked." )
36+
37+ # # create objects (instances) of the Car class
38+ # camry_car = Car("Toyota", "Camry", 2020, "Blue")
39+ # civic_car = Car("Honda", "Civic", 2019, "Red")
40+
41+ # # access attributes
42+ # print(camry_car.make) # Output: Toyota
43+ # print(civic_car.model) # Output: Civic
44+ # print(camry_car.year) # Output: 2020
45+ # # call methods
46+ # camry_car.drive(camry_car.make)
47+ # civic_car.park(civic_car.make)
48+ # camry_car.left_turn(camry_car.make)
49+ # civic_car.right_turn(civic_car.make)
50+ # camry_car.stop(camry_car.make)
51+ # civic_car.drive(civic_car.make)
0 commit comments