判断类型
class Monster:
def __init__(self, hp=100):
self.hp = hp
def run(self):
print('run')
def who_am_i(self):
print('fu lei')
class Animals(Monster):
def __init__(self, hp=11):
super().__init__(hp)
class Boss(Monster):
def __init__(self, hp=1000):
super().__init__(hp)
def who_am_i(self):
print('boss')
a1 = Monster()
a2 = Animals()
a3 = Boss()
print(type(a1))
print(type(a2))
print(type(a3))
判断继承关系
class Monster:
def __init__(self, hp=100):
self.hp = hp
def run(self):
print('run')
def who_am_i(self):
print('fu lei')
class Animals(Monster):
def __init__(self, hp=11):
super().__init__(hp)
class Boss(Monster):
def __init__(self, hp=1000):
super().__init__(hp)
def who_am_i(self):
print('boss')
a1 = Monster()
a2 = Animals()
a3 = Boss()
print(isinstance(a2, Monster))
# 输出
True