-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop.py
More file actions
65 lines (53 loc) · 1.27 KB
/
oop.py
File metadata and controls
65 lines (53 loc) · 1.27 KB
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
56
57
58
59
60
61
62
63
#first
stuff = list()
stuff.append('python')
stuff.append('chuck')
stuff.sort()
print (stuff[0])
print(stuff.__getitem__(0))
print(list.__getitem__(stuff,0))
# print(dir(stuff))
#second-class; constructors and destructors
class PartyAnimal:
x = 0
y = 5
name = ''
def __init__(self,name):
self.name = name
print(self.name,"is constructed as","x =",self.x,"y =",self.y)
def party(self):
self.x = self.x + 1
print(self.name, "so far has x as",self.x)
def teaparty(self,y):
self.y = self.y + y
print(self.name, "has y =",self.y)
def __del__(self):
print(self.name, "has destructed x =",self.x,"y =",self.y)
# an = PartyAnimal()
# an.party()
# an.teaparty(10)
# print("an is ",an)
# an = 50 #The --del-- is called now and our variables are discarded
# print("now an is",an)
class executing(PartyAnimal):
points = 0
def easy(self):
self.points = self.points + 6
self.party()
self.teaparty(1000)
print(self.name,"points",self.points)
s = PartyAnimal('Sally')
s.party()
s.teaparty(10)
print("----------")
j = PartyAnimal('Jim')
j.party()
j.teaparty(20)
print("-----------")
s = executing('Sally')
j = executing('Jim')
s.easy()
j.easy()
print("-----------")
s = 20
j = 20