🧭Inheritance
Also known as Subclass, Child Class, Parent Class
A new class that gets all of an old class's parts, then adds its own.
Think of it like
Think of it like a kid with a parent's eyes. The kid learns new tricks too.
Example
Why it matters
Definition
Example code
python
class Animal:
def breathe(self):
return "in, out"
class Cat(Animal):
pass
print(Cat().breathe()) # in, outCommon mistake
Key takeaways
- 1Parent and child. The child gets it all.
- 2Add or change. The child can do more.
- 3Keep chains short. Deep ones get confusing.