Advertisement
fkudinov

ООП із Словників та Функцій / Стандартна реалізація

Apr 4th, 2024
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | Source Code | 0 0
  1.  
  2. class PersonBase:
  3.     employment = "Unemployed"
  4.  
  5.     def __init__(self, name, employment=None):
  6.         self.name = name
  7.         if employment is not None:
  8.             self.employment = employment
  9.  
  10.     def greeting(self):
  11.         print("My name {}, and I am a {}".format(
  12.             self.get_name(),
  13.             self.get_employment()
  14.         ))
  15.  
  16.     def get_name(self):
  17.         return self.name
  18.  
  19.     def get_employment(self):
  20.         return self.employment
  21.  
  22.  
  23. person_1 = PersonBase("John", "Doctor")
  24. # person_1 = type.__call__(PersonBase, "John", "Doctor")
  25.  
  26. person_2 = PersonBase("Mathew", "Teacher")
  27. # person_2 = type.__call__(PersonBase, "Mathew", "Teacher")
  28.  
  29. person_3 = PersonBase("Mathew")
  30. # person_3 = type.__call__(PersonBase, "Mathew")
  31.  
  32. person_1.greeting()
  33. person_2.greeting()
  34. person_3.greeting()
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement