-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-class-n-objects.py
More file actions
52 lines (36 loc) · 994 Bytes
/
python-class-n-objects.py
File metadata and controls
52 lines (36 loc) · 994 Bytes
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
class Kettle():
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", 8.99)
print(kenwood.make)
print(kenwood.price)
kenwood.price = 12.75
print(kenwood.price)
print("*" * 80)
hamilton = Kettle("Hamilton", 14.55)
print(hamilton.make)
print(hamilton.price)
print("*" * 80)
print("Models: {} = {}, {} = {}".format(kenwood.make, kenwood.price, hamilton.make, hamilton.price))
print("Models: {0.make} = {0.price}, {1.make} = {1.price}".format(kenwood, hamilton))
print(kenwood.on)
Kettle.switch_on(kenwood)
print(kenwood.on)
kenwood.power = 1.5
print("*" * 80)
print(hamilton.on)
Kettle.switch_on(hamilton)
print(hamilton.on)
print("*" * 80)
print(Kettle.power_source)
print(kenwood.power_source)
print(hamilton.power_source)
print("*" * 80)
print(Kettle.__dict__)
print(kenwood.__dict__)
print(hamilton.__dict__)