isinstance
判断一个对象是否是另外一个类的实例,返回布尔值。
- 是:True
- 否:False
class Foo:
pass
class Boo:
pass
foo_obj = Foo()
boo_obj = Boo()
print(isinstance(foo_obj, Foo))
print(isinstance(boo_obj, Foo))
>>>True
>>>False
issubclass
判断一个类是否是另外一个类的子类,返回布尔值。
- 是:True
- 否:False
class Father:
pass
class Sub(Father):
pass
class Foo:
pass
print(issubclass(Sub, Father))
print(issubclass(Foo, Father))
>>>True
>>>False