Python - Inheritance
Code Life
By Pierre Marsaa
What is Inheritance?
Imagine all Codémon share some things (name, level, HP), but each type has something special. Water Codémon have a swim() method, Fire ones have burn(). Instead of rewriting everything, you can create a parent class and have children inherit from it.
Inheritance means a child class gets all the attributes and methods of its parent class — for free!
↗️
Loading editor...
↶
↷
WaterCodemon(Codemon) — the parentheses mean "inherits from Codemon". Even though WaterCodemon is empty (pass), it already has __init__ and __str__ from the parent!
Verify