Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyTypeSub
#python 3.6.9 #PyTypeSub:creating subclass using type #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; #creating a subclass using class keyword: class Cook(object): def __init__(self, kind): self.kind = kind def getKind(self): return self.kind class BakCook(Cook): def BakCooks(self): return {'Dry Cake','Vanilla Cake'} def main(): kind = BakCook(kind = 'Baked') print(kind.getKind()) print(kind.BakCooks()) 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, }) def BakCooks(self): return { 'Dry Cake','Fruit Cake'} ##creating subclass using type: BakCook = type('BakCook',(Cook,),{'BakCooks':BakCooks}) kind = BakCook(kind='Baked') print(kind.getKind) print(kind.BakCooks())
run
|
edit
|
history
|
help
0
lesson 6 final
Idd or even
3-6.격자판 최대합
Select fruits
multiple inheritance
gj
16jan
emoji
Tax task
Python: String to Brainfuck