Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyTeleAbs
#python 3.6.9 #PyTeleAbs: example of abstract class,abstract method and private method #this code is created by Rezaul Hoque on April 11,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; from abc import ABC,abstractmethod class Person(ABC): def __init__(self,first, last,num): self.first = first self.last = last self.num=num @property def filast(self): return f"{self.first} \t {self.last}\t{self.num}" @abstractmethod def category(self): pass class Professional(Person): def __init__(self,first,last,num,cat): super().__init__(first,last,num) self.cat = cat def category(self): return self.cat class Personal(Person): def __init__(self,first,last,num,cat): super().__init__(first,last,num) self.cat = cat def category(self): return self.cat class Detail: def __init__(self): self.booklist= [ ] def add(self,tel): self.booklist.append(tel) #private method def __banner(self): print("Example: Abstract class,abstract method and private method") print("~"*35) print("~"*35) print("name(first,last) number category \n") def display(self): for i in self.booklist: ##important:string objects are not callable like i.filast();they should be called like i.filast print(f"{i.filast}\t{i.category()}") if __name__ == '__main__': det = Detail() det._Detail__banner() det.add(Professional('hh','cc',4321,'former')) det.add(Professional('tt','nn',000,'current')) det.add(Personal('yy','mm',321,'personal')) det.display()
run
|
edit
|
history
|
help
0
Python_Hello_World
Komalsri123
E
calcultion
cls_var und cls_method
PYTHON 3
linked_lists_2+decisions
Student
75
Python3 - PDF PAGES SEPARATION