Skip to content
Advertisement

What argument ‘isinstance’ takes on declaring ‘k’ object?

JavaScript

So I have difficulties with understanding why isinstance evaluating True in this code. I see it as int is checking against class, which makes no sense to me.

Advertisement

Answer

Looking at this article about isinstance:

The isinstance() function returns True if the specified object is of the specified type, otherwise False.

In m‘s definition:

JavaScript

You’re passing 1 as the value of x_or_obj. 1 is an integer, not a Point, therefore it evaluates to False.

However, in k‘s definition:

JavaScript

you’re passing m as the value of x_or_obj. You earlier defined m as type Point, so isinstance evaluates to True.

Advertisement