Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitec9c83d

Browse files
committed
Add demo for class data scalability (in class Man_from_moon)
1 parent9971a8c commitec9c83d

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

‎SimpleOOP/src/simpleoop.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,39 @@ def series(self):
2626
yieldself.b
2727
self.a,self.b=self.b,self.a+self.b
2828

29-
classMouth():
29+
classMouth:
3030
def__init__(self):
3131
print('Constructor is called while object is defined.')
3232
defspeak(self):
3333
print('Mouth can speak.')
3434
defsing(self):
3535
print('Mouth can sing.')
3636

37+
classMan_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+
defget_face(self):
44+
print('Getting the face of man from moon')
45+
print('This makes it with limited scalability')
46+
returnself.variables.get('face',None)# default value returned for face is None
47+
48+
defset_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+
defget_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+
returnself.variables.get(k,None)# default value of 'None' is returned if variable not defined
57+
58+
defset_variable(self,k,v):
59+
print('Key-value argument makes the class model easily scalable in python.')
60+
self.variables[k]=v
61+
3762
defmain():
3863
# instantiate: make object of the class
3964
f=Fibonacci(0,1)
@@ -46,5 +71,16 @@ def main():
4671
my_mouth=Mouth()# my_mouth = object of the class Mouth
4772
my_mouth.speak()
4873
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('\nAddressing 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+
5086
if__name__=='__main__':main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp