-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path160 Object Oriented Programming.py
55 lines (37 loc) · 1.04 KB
/
160 Object Oriented Programming.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Kettle(object):
power_source = "electricity"
def __init__(self, make, price):
self.make = make
self.price = price
self.on = False
def switch_on(self):
self.on = True
kenwood = Kettle("Kenwood", 10.99)
print(kenwood.make)
print(kenwood.price)
kenwood.price = 12.75
print(kenwood.price)
hamilton = Kettle("hamilton", 14.99)
print("Modele: {} = {}, {} = {}".format(kenwood.make, kenwood.price, hamilton.make, hamilton.price))
print("Modele {0.make} = {0.price}. {1.make} = {1.price}".format(kenwood, hamilton))
print(hamilton.on)
hamilton.switch_on()
print(hamilton.on)
Kettle.switch_on(kenwood)
print(kenwood.on)
kenwood.switch_on = False
print(kenwood.switch_on)
print("*" * 60)
kenwood.power = 1.5
print(kenwood.power)
#print(hamilton.power)
Kettle.power_source = "atomic"
print(Kettle.power_source)
print(kenwood.power_source)
print(hamilton.power_source)
# change one
kenwood.power_source = "gas"
print(kenwood.power_source)
print(Kettle.__dict__)
print(kenwood.__dict__)
print(hamilton.__dict__)