forked from raun1997/Packt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstance.py
41 lines (29 loc) · 930 Bytes
/
instance.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
36
37
38
39
40
41
class Car:
# Class variables
vehicle_type = "suv"
model = "S90"
# Constructor method with instance variables brand and cost
def __init__(self, brand, cost):
self.brand = brand
self.cost = cost
# Method with instance variable followers
def fan_follow(self, follow):
print("This user has " + str(follow) + " follow")
def main():
# First object, set up instance variables of constructor method
car = Car("Volvo", 7)
# Print out instance variable brand
print(car.brand)
# Print out class variable cost
print(car.cost)
# Second object
suv = Car("Audi", 15)
# Print out instance variable brand
print(suv.brand)
print(suv.cost)
# Use set_followers method and pass followers instance variable
suv.fan_follow(77)
# Print out class variable vehicle_type
print(suv.vehicle_type)
if __name__ == "__main__":
main()