class Foo(object): pass class Bar(Foo): pass obj = Bar() # isinstance用于判断,对象是否是指定类的实例 (错误的) # isinstance用于判断,对象是否是指定类或其派生类的实例 print(isinstance(obj,Foo)) #True print(isinstance(obj,Bar))#True #精确的 print(type(obj) == Bar) #True print(type(obj) == Foo) #False
时间: 2024-10-20 22:17:03