-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSuperclass Examples.py
More file actions
321 lines (245 loc) · 8.73 KB
/
Superclass Examples.py
File metadata and controls
321 lines (245 loc) · 8.73 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# These superclass examples are also my own tinkering from other such examples. However, super() and __init__
# constructors are still very new to me. So please don't ask me how to understand what I made, because I honestly don't.
# Well, I understand classes and functions, but the super() function is very new to me. But, I'm pretty darn sure I
# will figure it all out in due time...
class Super_class:
def super1(self):
print('Super1')
def super2(self):
print('Super2')
def super3(self):
print('Super3')
class Class_all(Super_class):
def get_values(self):
super().super1()
super().super2()
super().super3()
Class_all().get_values()
'''-----------------------------------------------------------------------------'''
class Super:
def person(self):
print('person(self) is from Super class')
def home(self):
print('home(self) is from Super class')
class Sub:
def pet(self):
print('pet(self) is from Sub class')
def toys(self):
print('toys(self) is from Sub class')
class Class_all(Super,Sub):
def get_all(self):
super().person()
super().home()
super().pet()
super().toys()
Class_all().get_all()
'''-----------------------------------------------------------------------------'''
class Super_class:
def __init__(self,value1,value2,value3):
self.value1=value1
self.value2=value2
self.value3=value3
class Super_sub(Super_class):
def __init__(self,value1,value2,value3):
super().__init__(value1,value2,value3)
a=Super_class('value1','value2','value3')
print(f'{a.value1}, {a.value2} and {a.value3}')
'''-----------------------------------------------------------------------------'''
class Super_class:
def __init__(self,value1,value2,value3):
self.value1=value1
self.value2=value2
self.value3=value3
class Super_sub(Super_class):
def __init__(self,value1,value2,value3):
super().__init__(value1,value2,value3)
super_class_string=[
Super_class('John','dog',4),
Super_class('Tom','cat',7),
Super_class('Bob','bird',4),
Super_class('Ron','fish',9)
]
print(f'{super_class_string[0].value1} is {super_class_string[0].value3} \
years old, and he loves his {super_class_string[0].value2} very much.')
a=super_class_string
print(f'{a[0].value1} is {a[0].value3} years old, and he loves his {a[0].value2} \
very much.')
for i in super_class_string:
print(f'{i.value1} is {i.value3} years old, and he loves his {i.value2} very much.')
'''-----------------------------------------------------------------------------'''
class Super1:
def __init__(self,value1,value2,value3,value4):
self.var1=value1
self.var2=value2
self.var3=value3
self.var4=value4
class Super2(Super1):
def __init__(self,var1,var2,var3,var4):
super().__init__(var1,var2,var3,var4)
class Super3(Super1):
def __init__(self,var1,var2,var3,var4):
super().__init__(var1,var2,var3,var4)
class Super4(Super1):
def __init__(self,var1,var2,var3,var4):
super().__init__(var1,var2,var3,var4)
print(Super1('value1','value2','value3','value4').var1)
print(Super2('value1','value2','value3','value4').var2)
print(Super3('value1','value2','value3','value4').var3)
print(Super4('value1','value2','value3','value4').var4)
a=Super1('value1','value2','value3','value4')
b=Super2('value1','value2','value3','value4')
c=Super3('value1','value2','value3','value4')
d=Super4('value1','value2','value3','value4')
print(a.var1,b.var2,c.var3,d.var4)
'''-----------------------------------------------------------------------------'''
class Student_body:
def __init__(
self,value1,
value2,value3,
value4,value5):
self.var1=value1
self.var2=value2
self.var3=value3
self.var4=value4
self.var5=value5
class First_name(Student_body):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
class Middle_name(Student_body):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
class Last_name(Student_body):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
class Student_age(Student_body):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
class Student_grade(Student_body):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
class Students(Student_body):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
a=First_name(
'First name1',
'First name2',
'First name3',
'First name4',
'First name5'
)
b=Middle_name(
'Middle name1',
'Middle name2',
'Middle name3',
'Middle name4',
'Middle name5'
)
c=Last_name(
'Last name1',
'Last name2',
'Last name3',
'Last name4',
'Last name5'
)
d=Student_age(22,18,17,20,19)
e=Student_grade(12,10,12,11,9)
print(e.var1)
'''-----------------------------------------------------------------------------'''
class Student_body:
def __init__(
self,value1,
value2,value3,
value4,value5):
self.var1=value1
self.var2=value2
self.var3=value3
self.var4=value4
self.var5=value5
class First_name(Student_body):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
class Middle_name(Student_body):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
class Last_name(Student_body):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
class Student_age(Student_body):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
class Student_grade(Student_body):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
class Students(Student_body):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
list_args=[
First_name(
'First name1','First name2',
'First name3','First name4',
'First name5'),
Middle_name(
'Middle name1','Middle name2',
'Middle name3','Middle name4',
'Middle name5'),
Last_name(
'Last name1','Last name2',
'Last name3','Last name4',
'Last name5'),
Student_age(22,18,17,20,19),
Student_grade(12,10,12,11,9)
]
print(f'Student {list_args[0].var1} {list_args[1].var1}. {list_args[2].var1}')
print(f'Student age:{list_args[3].var1} Student grad:{list_args[4].var1}')
'''-----------------------------------------------------------------------------'''
class Super_dooper:
def __init__(
self,value1,
value2,value3,
value4,value5):
self.var1=value1
self.var2=value2
self.var3=value3
self.var4=value4
self.var5=value5
class Super1(Super_dooper):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
class Super2(Super_dooper):
def __init__(self,var1,var2,var3,var4,var5):
super().__init__(var1,var2,var3,var4,var5)
a=Super2('value1','value2','value3','value4','value5')
print(a.var5)
'''-----------------------------------------------------------------------------'''
class A(object):
def __init__(self):
print('first')
class B(object):
def __init__(self):
print('second')
class C(A,B):
def __init__(self):
super().__init__()
print('third')
My_object=C()
'''-----------------------------------------------------------------------------'''
class Super1:
def first(self):
print('Super1')
class Super2:
def second(self):
print('Super2')
class Super3:
def third(self):
print('Super3')
class Super4:
def forth(self):
print('Super4')
class Child(Super1,Super2,Super3,Super4):
def allclass(self):
print('lets call all the classes at once.')
super().first()
super().second()
super().third()
super().forth()
Child().allclass()