@@ -26,14 +26,39 @@ def series(self):
26
26
yield self .b
27
27
self .a , self .b = self .b , self .a + self .b
28
28
29
- class Mouth () :
29
+ class Mouth :
30
30
def __init__ (self ):
31
31
print ('Constructor is called while object is defined.' )
32
32
def speak (self ):
33
33
print ('Mouth can speak.' )
34
34
def sing (self ):
35
35
print ('Mouth can sing.' )
36
36
37
+ class Man_from_moon ():
38
+ def __init__ (self , ** kargs ):
39
+ print ('This class defines the scalability of the class data.' )
40
+ print ('Use of dictoionaries in class variable definition can make the class data scalable easily.' )
41
+ self .variables = kargs
42
+
43
+ def get_face (self ):
44
+ print ('Getting the face of man from moon' )
45
+ print ('This makes it with limited scalability' )
46
+ return self .variables .get ('face' , None ) # default value returned for face is None
47
+
48
+ def set_face (self , face ):
49
+ print ('Setting the face of man from moon' )
50
+ print ('This makes it with limited scalability' )
51
+ self .variables ['face' ] = face
52
+
53
+ def get_variable (self , k ):
54
+ # k is the name of the varible
55
+ print ('using the key word variables to set and get makes it easier to deal with scalibility of class data' )
56
+ return self .variables .get (k , None ) # default value of 'None' is returned if variable not defined
57
+
58
+ def set_variable (self , k , v ):
59
+ print ('Key-value argument makes the class model easily scalable in python.' )
60
+ self .variables [k ] = v
61
+
37
62
def main ():
38
63
# instantiate: make object of the class
39
64
f = Fibonacci (0 ,1 )
@@ -46,5 +71,16 @@ def main():
46
71
my_mouth = Mouth () # my_mouth = object of the class Mouth
47
72
my_mouth .speak ()
48
73
my_mouth .sing ()
49
-
74
+
75
+ # class data scalability discussed and demonstrated
76
+ marty = Man_from_moon (face = 'MoonFace' , intelligence = 'HighIntell' )
77
+ print ('Getting face value from constructor: ' , marty .get_face ())
78
+ marty .set_face ('ManFace' )
79
+ print ('Getting face value from Getter Method: ' , marty .get_face ())
80
+ print ('\n Addressing Scalability:' )
81
+ print ('Getting value of \' face\' constructor:' , marty .get_variable ('face' ))
82
+ print ('Getting value of \' intelligence\' set in constructor:' , marty .get_variable ('intelligence' ))
83
+ marty .set_variable ('intelligence' , 'VeryHighIntell' )
84
+ print ('Getting new value of \' intelligence\' :' , marty .get_variable ('intelligence' ))
85
+
50
86
if __name__ == '__main__' : main ()
0 commit comments