I have created 2 classes A & B, B inherits A. I'm using the isinstance to check if b is of type a and it returns false. Shouldn't be true?
class a():pass
class b(a):pass
print isinstance(b,a)
I have created 2 classes A & B, B inherits A. I'm using the isinstance to check if b is of type a and it returns false. Shouldn't be true?
class a():pass
class b(a):pass
print isinstance(b,a)
No. b
is an instance of either type
or classobj
, not of a
. You may want the issubclass
function instead.
>>> issubclass(b, a)
True
b is class, not object, so it is not instance of any class. To get True, call isinstance(b(),a)