Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Pets:
- subclasses = []
- def __init_subclass__(cls, **kwargs):
- super().__init_subclass__(**kwargs)
- cls.subclasses.append(cls)
- class Dog(Pets):
- def speak(self):
- print("woof")
- class Cat(Pets):
- def speak(self):
- print("meow")
- doggo = Dog()
- doggo.speak()
- cat = Cat()
- cat.speak()
- my_pets = Pets()
- my_pets.subclasses
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement