0

I am familiar with the difference between type(x) and x.__class__ but couldn't find an answer to the question if there is any difference between these two ways of checking whether x is, say, a dictionary:

isinstance(x, dict)

x.__class__ == dict

So far, in my experience, the two can be used interchangeably but I would like to know whether there are cases where the results differ, giving rise to a preference for one of both.

Edit: alaniwi gave the accepted answer that isinstance() also returns True if the object is an instance of a subclass of the class tested against.

0 Answers0