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
原文地址:https://www.cnblogs.com/konglingxi/p/9591367.html
时间: 2024-10-11 21:56:54