day22_isinstance和issubclass
目录
1、isinstance(object,class or subclass)
2、issubclass(class,class or subclass)
# 1
# 判断一个对象是不是某个类的实例化,或者这个对象的类是不是继承于某个类
class Foo:
pass
class Boo(Foo):
pass
foo = Foo()
boo = Boo()
print(isinstance(foo,Foo)) # foo是Foo的实例化
print(isinstance(foo,object)) # foo所属的类是Foo,Foo继承于object
print(isinstance(boo,Boo))
print(isinstance(boo,Foo))
print(isinstance(foo,Boo))
'''
True
True
True
True
False'''
# 2
# 判断一个类是不是等于一个类或者是一个类的子类
class Foo:
pass
class Boo:
pass
print(issubclass(Foo,Foo))
print(issubclass(Foo,Boo))
print(issubclass(Foo,object))
'''
True
False
True'''