python内建函数isinstance和issubclass

isinstance,issubclass


isinstance

isinstance用来判断一个对象是否属于一个类

issubclass

issubclass用来判断一个类是否继承于另一个类

使用例子

```python
class A:
    pass
class B(A):
    pass
class C:
    pass
print(issubclass(B,A)) #判断B是否继承于A
b = C()
print(isinstance(b, C)) #判断对象b是否属于C
'''
output:
True
True
'''
```

Leave a Reply

Your email address will not be published. Required fields are marked *