obj type():
isinstance(obj2, type(obj1))
, , . type() , .
issubclass() :
issubclass(type(obj2), Item)
:
>>> class Item:
... def __init__(self,a):
... self.a=a
...
>>> class Sub(Item):
... def __init__(self,a,b):
... self.b=b
... Item.__init__(self,a)
...
>>> class SubSub(Sub):
... def __init__(self,a,b,c):
... self.c=c
... Sub.__init__(self,a,b)
...
>>> obj1=Item(1)
>>> obj2=Sub(1,2)
>>> obj3=SubSub(1,2,3)
>>> isinstance(obj2, type(obj1))
True
>>> issubclass(type(obj2), Item)
True
, , , . type(obj2) , , , , , .
, ; , , :
>>> type(obj1) is Item
True
>>> type(obj2) is Sub
True
>>> type(obj3) is SubSub
True