Advertisement
Guest User

Untitled

a guest
Sep 25th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. class Pets:
  2. subclasses = []
  3.  
  4. def __init_subclass__(cls, **kwargs):
  5. super().__init_subclass__(**kwargs)
  6. cls.subclasses.append(cls)
  7.  
  8. class Dog(Pets):
  9. def speak(self):
  10. print("woof")
  11.  
  12. class Cat(Pets):
  13. def speak(self):
  14. print("meow")
  15.  
  16.  
  17. doggo = Dog()
  18. doggo.speak()
  19. cat = Cat()
  20. cat.speak()
  21. my_pets = Pets()
  22. my_pets.subclasses
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement