class Foo(object): pass class Bar(Foo): pass obj = Bar() # isinstance用于判断,对象是否是指定类或其派生类的实例 print(isinstance(obj,Foo)) #True print(isinstance(obj,Bar))#True #精确的判断对象是否是指定类的实例 print(type(obj) == Bar) #True print(type(obj) == Foo) #False
2024-02-25 14:42:57
class Foo(object): pass class Bar(Foo): pass obj = Bar() # isinstance用于判断,对象是否是指定类或其派生类的实例 print(isinstance(obj,Foo)) #True print(isinstance(obj,Bar))#True #精确的判断对象是否是指定类的实例 print(type(obj) == Bar) #True print(type(obj) == Foo) #False