Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PySlots3
#python 3.6.9 #PySlots3: Demonstration of subclass uses slots but base class doesn't and how to use private method #this code is created by Rezaul Hoque on January 09,2022;contact: jewelmrh@yahoo.com,Dhaka, Bangladesh #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; class Food: def __init__(self, food,color): self.food = food self.color = color class CookedFood(Food): __slots__= ('price',) def __init__(self,food,color,price): super().__init__(food,color) self.price = price def __banner(self): print("Example: Subclass uses slots but base class doesn't") if __name__ == '__main__': ic= CookedFood('Icecream','white',10) ic._CookedFood__banner() print (ic.__slots__) print(ic.__dict__) ic.taste='good' print(ic.__dict__)
run
|
edit
|
history
|
help
0
Rectangle Perimiter
Lesso#6 updated
linked_lists_2+decisions
lesson3 part3
pythonfin
Hi
library
Rene
StAr
Lesson 9 hw