issubclass(sub, super)
判断第一个类是不是第二个类的的子类; 是则返回True
否则返回False
class Foo:
pass
class Bar(Foo):
pass
# 以元组的方式查看Bar类的所以父类
print(Bar.__bases__)
# 这里做判断
print(issubclass(Bar, Foo))
print(issubclass(Foo, Bar))
class xh(Bar):
pass
print(issubclass(xh, Foo))
isinstance(obj, cls)
判断第一个参数是不是第二个参数的对象, 是则返回True,否则返回False
class Foo:
pass
class XH:
pass
f = Foo()
print(isinstance(f, Foo))
print(isinstance(f, XH))
标签:isinstance,Bar,用法,issubclass,pass,print,Foo
From: https://www.cnblogs.com/hanyingshuo/p/17797417.html