判断对象的方法_isinstance
描述
isinstance(): 判断一个对象是否是由一个类创建出来的,是则返回True,否则返回False
语法:isinstance(对象,类)
示例代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
s = 'hello' class Demo(object): pass demo = Demo() print(isinstance(demo,Demo)) # True print(isinstance(s,Demo)) # False
isinstance(): 判断一个对象是否是由一个类创建出来的,是则返回True,否则返回False
语法:isinstance(对象,类)
s = 'hello' class Demo(object): pass demo = Demo() print(isinstance(demo,Demo)) # True print(isinstance(s,Demo)) # False