Quick actions

cmd+k|ctrl+k

Navigation

Languages

Class:Inheritance

Snippet info

Language

Python

Visibility

public

Author

bensruthy

Created

2026-03-23T02:48:50.717164Z

Updated

2026-03-23T02:48:50.717164Z

# Inheritance

# Parent Class
class User:
    def sign_in(self):
        print('logged in')


# Sub Class/ Child Class/ Derived Class
class Wizard(User):
    def __init__(self, name, power):
        self.name = name
        self.power = power

    def attack(self):
        print(f'Attacking with power of {self.power}')


class Archer(User):
    def __init__(self, name, num_arrows):
        self.name = name
        self.num_arrows = num_arrows

    def attack(self):
        print(f'Attacking with arrows: Arrows left- {self.num_arrows}')


wizard1 = Wizard('Merlin', 50)
archer1 = Archer('Robbin', 100)
wizard1.attack()
archer1.attack()
archer1.sign_in()

print(isinstance(wizard1, Wizard))
print(isinstance(wizard1, User))
print(isinstance(wizard1, object))
INFO