-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathChild_all class inner functions.py
More file actions
629 lines (446 loc) · 14 KB
/
Child_all class inner functions.py
File metadata and controls
629 lines (446 loc) · 14 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
# Type and execute/run this child_all class inner functions
# program example below and play around with different
# combinations of how to display the output.
class Math:
def nums(num1,num2,num3):
return num1**num2*num3
class Reading:
def words(word1,word2,word3):
return word2
class Science:
def people(person1,person2,person3):
return person2
class Child_all(Math,Reading,Science):
pass
'''----------------------------------------------------------------'''
# Try these different combination examples.
print(Math.nums(9,2,2))
print(Reading.words('word1','word2','word3'))
print(Science.people(
'Albert Einstein',
'Isaac Newton',
'Stephen Hawking'))
# The 'Child_all' class inherits all the other classes,
# which means any of these class function values can
# be called.
print(Child_all.nums(9,2,2))
print(Child_all.words('word1','word2','word3'))
print(Child_all.people(
'Albert Einstein',
'Isaac Newton',
'Stephen Hawking'))
# Create some strings to shorten your code.
m=Child_all.nums(9,2,2)
r=Child_all.words('word1','word2','word3')
s=Child_all.people(
'Albert Einstein',
'Isaac Newton',
'Stephen Hawking')
print(m,r,s)
print(m*m,r,s)
# Old format:
print('{} counts to {} and uses {}'.format(s,m*m,r))
# New format with the 'f' function:
print(f'{s} counts to {m*m} and uses {r}')
'''---------------------------------------------------------------------------------------'''
# Type and execute/run this child_all class inner functions
# program example below and play around with different
# combinations of how to display the output.
class Addition:
def nums1(num1,num2,num3):
return num1+num2+num3
class Subtraction:
def nums2(num1,num2,num3):
return num1-num2-num3
class Multiplication:
def nums3(num1,num2,num3):
return num1*num2*num3
class Division:
def nums4(num1,num2,num3):
return num1/num2/num3
class Child_all(
Addition,Subtraction,
Multiplication,Division):
pass
'''----------------------------------------------------------------'''
# Try these different combination examples.
print(Addition.nums1(1,2,3))
print(Subtraction.nums2(1,2,3))
print(Multiplication.nums3(1,2,3))
print(Division.nums4(1,2,3))
# The 'Child_all' class inherits all the other classes,
# which means any of these class function values can
# be called.
print(Child_all.nums1(1,2,3))
print(Child_all.nums2(1,2,3))
print(Child_all.nums3(1,2,3))
print(Child_all.nums4(1,2,3))
'''----------------------------------------------------------------'''
# Create some strings to shorten your code.
a=Addition.nums1(1,2,3)
b=Subtraction.nums2(1,2,3)
c=Multiplication.nums3(1,2,3)
d=Division.nums4(1,2,3)
print(a+b+c+d*3)
'''----------------------------------------------------------------'''
# Create some strings to shorten your code.
a=Child_all.nums1(1,2,3)
b=Child_all.nums2(1,2,3)
c=Child_all.nums3(1,2,3)
d=Child_all.nums4(1,2,3)
print(a+b+c+d*5)
'''---------------------------------------------------------------------------------------'''
# Pass name strings in functions and return
# their values.
def name(
name1='"Python',
name2='Programmer\'s',
name3='Glossary',
name4='Bible"'):
# Old format:
return '{} {} {} {}'.format(name1,name2,name3,name4)
print(name())
def name(
name1='"Python',
name2='Programmer\'s',
name3='Glossary',
name4='Bible"'):
# New format with the 'f' function:
return f'{name1} {name2} {name3} {name4}'
print(name())
'''---------------------------------------------------------------------------------------'''
# Now, let's pass some of our own string values '"Monty
# Python' and 'is the best' right inside the 'print' statement.
def name(
name1='"Python',
name2='Programmer\'s',
name3='Glossary',
name4='Bible"'):
# New format with the 'f' function:
return f'{name1} {name2} {name3} {name4}'
print(name('"Monty Python','is the best'))
# Let's creat a string variable for our 'print' statement.
string=name('"Monty Python','is the best')
print(string)
'''---------------------------------------------------------------------------------------'''
# Create a class called 'All_names' which inherits
# all the properties of the 'Inherit' class
class Inherit:
def person1(self):
print('Albert Einstein')
def person2(self):
print('Isaac Newton')
def person3(self):
print('Stephen Hawking')
def math(num1,num2):
return num1+num2
class All_names(Inherit):
pass
All_names.person1('')
All_names.person2('')
All_names.person3('')
print(All_names.math(2,8))
# Call the 'Inherit' class properties and notice
# how they have the very same property values
# as in the class 'All_names'.
Inherit.person1('')
Inherit.person2('')
Inherit.person3('')
print(Inherit.math(2,8))
'''---------------------------------------------------------------------------------------'''
# Create functions with for-loops inside them and then
# call the 'Inherit' class values and the 'All_loops' class
# values.
class Inherit:
def loop1():
for i in range(10):
print('Number',i+1)
def loop2():
for i in range(10):
print('Create another loop inside a function')
def loop3():
for i in range(1,11,1):
print('* '*i,i)
class All_loops(Inherit):
pass
All_loops.loop1()
All_loops.loop2()
All_loops.loop3()
# Call the 'Inherit' class properties and notice
# how they have the very same property values
# as in the class 'All_loops'.
Inherit.loop1()
Inherit.loop2()
Inherit.loop3()
'''---------------------------------------------------------------------------------------'''
# Below is a quick map example of what class inheritance
# looks like. The 'pass' function is just a simple function that
# occupies the empty code blocks, so that Python will ignore
# these empty code blocks.
class Inherit1:
pass
class Inherit2:
pass
class Inherit3:
pass
class Inherit_all(Inherit1,Inherit2,Inherit3):
pass
# Notice how the class inheritance program below is the same
# as our quick map example above. The empty code blocks now
# have some 'def' functions and some 'print' statements in them
# instead of the 'pass' function.
class Inherit1:
def words1():
print('Inherit1 prints out words1')
def words2():
print('Inherit1 prints out words2')
def words3():
print('Inherit1 prints out words3')
class Inherit2:
def words4():
print('Inherit2 prints out words4')
def words5():
print('Inherit2 prints out words5')
def words6():
print('Inherit2 prints out words6')
class Inherit3:
def words7():
print('Inherit3 prints out words7')
def words8():
print('Inherit3 prints out words8')
def words9():
print('Inherit3 prints out words9')
class Inherit_all(Inherit1,Inherit2,Inherit3):
pass
# Call the 'Inherit1' class properties and notice how they have
# the very same property values as in the class 'Inherit_all'.
Inherit1.words1
Inherit1.words2
Inherit1.words3
Inherit2.words4
Inherit2.words5
Inherit2.words6
Inherit3.words7
Inherit3.words8
Inherit3.words9
# Call the 'Inherit_all' class properties and notice how they have
# the very same property values as in the class 'Inherit1' properties.
Inherit_all.words1()
Inherit_all.words2()
Inherit_all.words3()
Inherit_all.words4()
Inherit_all.words5()
Inherit_all.words6()
Inherit_all.words7()
Inherit_all.words8()
Inherit_all.words9()
'''----------------------------------------------------------------'''
# Now, let's create a 'tuple' for our class inheritance loop.
inherit_loop=(
Inherit_all.words1(),Inherit_all.words2(),
Inherit_all.words3(),Inherit_all.words4(),
Inherit_all.words5(),Inherit_all.words6(),
Inherit_all.words7(),Inherit_all.words8(),
Inherit_all.words9()
)
# Next, let's create a for-loop, which will loop through
# the 'tuple' values instead of having to manually type
# all that redundant code, line by line. The 'pass' function
# is just a simple function that occupies the empty code
# blocks, so that Python will ignore these empty code blocks.
for i in inherit_loop:
pass
'''---------------------------------------------------------------------------------------'''
class First_Name:
def first_name(self):
return self
def sec_name(self):
return self
class Last_Name:
def last_name(self):
return self
class Full_Name(First_Name,Last_Name):
pass
example1=First_Name.first_name('Example1')
example2=First_Name.sec_name('Example2')
example3=Last_Name.last_name('Example3')
a=Full_Name.first_name('Example1')
b=Full_Name.sec_name('Example2')
c=Full_Name.last_name('Example3')
print(example3)
'''---------------------------------------------------------------------------------------'''
class Person:
def __init__(self,name):
self.name=name
def talk(self):
print(f'Hi, I am {self.name}')
john=Person('John Smith')
bob=Person('Bob Smoth')
john.talk()
bob.talk()
'''---------------------------------------------------------------------------------------'''
class Mammal:
def walk(self):
print('walk')
class Dog(Mammal):
def bark(self):
print('bark')
class Cat(Mammal):
def be_annoying(self):
print('annoying')
Dog().bark()
Dog().walk()
Cat().walk()
Cat().be_annoying()
'''---------------------------------------------------------------------------------------'''
class First_Class:
def first():
print('First Class')
class Second_Class:
def second():
print('Second Class')
class Third_Class:
def third():
print('Third Class')
class Forth_Class:
def forth():
print('Forth Class')
class All_Classes(
First_Class,
Second_Class,
Third_Class,
Forth_Class
):pass
First_Class.first()
All_Classes.first()
'''---------------------------------------------------------------------------------------'''
class Book:
def book(
name1='"Python',
name2='Programmer\'s',
name3='Glossary',
name4='Bible"'
):
return f'{name1} {name2} {name3} {name4}'
class Author:
def author(
name1='By',
name2='Joesph',
name3='C.',
name4='Richardson'
):
return f'{name1} {name2} {name3} {name4}'
class Full_Name(Book,Author):
pass
a=Full_Name.book()
b=Full_Name.author()
print(a,b)
'''---------------------------------------------------------------------------------------'''
class Book:
def __init__(self,book1,book2):
self.book1=book1
self.book2=book2
def testing(book1,book2):
return book1
a=Book.testing('test1','test2')
b=Book('test1','test2').book2
print(a,b)
'''---------------------------------------------------------------------------------------'''
class Main_class:
def example1():
print('Main_class')
class Second_class:
def example2():
print('Second_class')
class Third_class:
def example3():
print('Third_class')
class Full_class(Main_class,Second_class,Third_class):
pass
Main_class.example1()
Second_class.example2()
Third_class.example3()
Full_class.example1()
Full_class.example2()
Full_class.example3()
'''---------------------------------------------------------------------------------------'''
class Class_one:
def __init__(self,value1,value2,value3):
self.value1=value1
self.value2=value2
self.value3=value3
class Class_two:
def __init__(self,value1,value2,value3):
self.value1=value1
self.value2=value2
self.value3=value3
class Class_three:
def __init__(self,value1,value2,value3):
self.value1=value1
self.value2=value2
self.value3=value3
class Class_all(Class_one,Class_two,Class_three):
pass
a=Class_one(
'Class_one value1',
'Class_one value2',
'Class_one value3'
)
b=Class_two(
'Class_two value1',
'Class_two value2',
'Class_two value3'
)
c=Class_three(
'Class_three value1',
'Class_three value2',
'Class_three value3'
)
d=Class_all(
'Class_all value1',
'Class_all value2',
'Class_all value3'
)
e=Class_all(
'Class_all value1',
'Class_all value2',
'Class_all value3'
)
f=Class_all(
'Class_all value1',
'Class_all value2',
'Class_all value3'
)
print(a.value1)
print(b.value2)
print(c.value3)
print(d.value1)
print(e.value2)
print(f.value3)
'''---------------------------------------------------------------------------------------'''
class Class_one:
def __init__(self,value1,value2,value3):
self.value1=value1
self.value2=value2
self.value3=value3
def get_return_value1(self):
return self
class Class_two:
def __init__(self,value1,value2,value3):
self.value1=value1
self.value2=value2
self.value3=value3
def get_return_value2(self):
return self
class Class_three:
def __init__(self,value1,value2,value3):
self.value1=value1
self.value2=value2
self.value3=value3
def get_return_value3(self):
return self
class Class_all(Class_one,Class_two,Class_three):
pass
a=Class_one('value1','value2','value3')
b=Class_all('value1','value2','value3')
print(b.value3)