Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyTypeClass
#python 3.6.9 #pyTypeClass: understanding the type class #this code is created by Rezaul Hoque on January 26,2022; #contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com #note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #following code is written with class keyword: # class Cook(object): def __init__(self, kind): self.kind = kind def getKind(self): return self.kind def main(): kind = Cook(kind = 'Fried') print(kind.getKind()) main() ### ##the above code is rewritten using type class: def __init__(self, kind): self.kind = kind def getKind(self): return self.kind Cook = type('Cook', (object, ), { '__init__': init, 'getKind' : getKind, })#type has 3 arguments: class name,tuple and a dictionary kind = Cook(kind='Fried') print(kind.getKind())
run
|
edit
|
history
|
help
0
binary search
E
Prac1_2
functions add
init constructor
validation
Hi.py
my first print
gj
75