Skip to content
← Python for AI/ML · all 50 levels

Inheritance

Level 49 of 50 · Objects & beyond

Level 49 of 50

Inheritance

children get the parent's code. Watch the reel, then work through it below: run the code, take the quiz, keep the cheat sheet.

📒 Open the cheat sheet
SanaEveryone says I have my father's nose!
TeacherClasses do that too! A child class gets the parent's code. Inheritance!
ride.py
class Ride:
    def fare(self):
        return 100
class Rickshaw(Ride):
    pass
r = Rickshaw()
print(r.fare())
TeacherRickshaw is empty, but it still has a fare!
SanaEmpty? So where did fare come from?
TeacherFrom the parent! (Ride) means: inherit everything Ride has.
ride.py
class Ride:
    def fare(self):
        return 100
class Careem(Ride):
    def fare(self):
        return 300
print(Careem().fare())
TeacherA child can also override. Careem writes its own fare!

⏸ Pause & predict: what prints?

class Phone:
    def ring(self):
        return "tring"
class Smart(Phone):
    def ring(self):
        return "beep"
print(Phone().ring())

Where this leads

Python is step one. Building AI that ships is the rest.

The diploma takes you from zero to deployed computer vision, LLM and agent projects, with engineers who build them for a living. Already code? The bootcamp does it in three months.