-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0x32-oop_intro.py
executable file
·35 lines (26 loc) · 977 Bytes
/
0x32-oop_intro.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python3
# we can use programming to mimic real world objects by assigning attributes(what an object is or has) and a method(what an object can do)
# we use classes. capitalized naming convention
# def __init__(self): method is a special method that will construct objects for us
# in other programming languages, it is known as the constructor
class Car:
def __init__(self, make, model, year, color):
# attributes
self.make = make
self.model = model
self.year = year
self.color = color
# methods -> self refers to the object that is using this method
def drive(self):
print("This car is driving")
print("This {} is indeed driving".format(self.model))
def stop(self):
print("This car has stopped")
# creating objects from classes
car_1 = Car("Chevy", "Corvette", 2021, "Blue")
print(car_1.make)
print(car_1.model)
print(car_1.year)
print(car_1.color)
car_1.drive()
car_1.stop()