I think, it is a kind of “__main__ vs. module_name” discrepancy -I hope I am using the right word-. I have tried to modify your code: test.py [...] if __name__=="__main__": # is dev object an instance of a PythonDeveloper Class print(isinstance(dev, PythonDeveloper)) print(dev.__cl… Answer from sandraC on discuss.python.org
🌐
W3Schools
w3schools.com › python › ref_func_isinstance.asp
Python isinstance() Function
Python Examples Python Compiler ... Python Training ... The isinstance() function returns True if the specified object is of the specified type, otherwise False....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-isinstance-method
isinstance() method - Python - GeeksforGeeks
July 11, 2025 - isinstance() is a built-in Python function that checks whether an object or variable is an instance of a specified type or class (or a tuple of classes), returning True if it matches and False otherwise, making it useful for type-checking and ...
Discussions

How to `isinstance` a typing type so that it works with static type checkers?
My code defines lots of typing types, and I need to isinstance lots of objects against them at runtime. Something like this: Type1 = list[int] Type2 = list[str] # etc. # get data from the outside, e.g. read from a … More on discuss.python.org
🌐 discuss.python.org
0
0
January 25, 2024
Isinstance() not working as expected when passing objects as arguments to functions (Inheretance)
When working on a project I stumbled upon a problem with isinstance(). I have made a simple example to ilustrate it: test.py import testAux class Developer(object): # Constructor def __init__(self, name): self.name = name class PythonDeveloper(Developer): # Constructor def __init__(self, name, ... More on discuss.python.org
🌐 discuss.python.org
2
0
May 13, 2022
python - What are the differences between type() and isinstance()? - Stack Overflow
To summarize the contents of other ... answers, isinstance caters for inheritance (an instance of a derived class is an instance of a base class, too), while checking for equality of type does not (it demands identity of types and rejects instances of subtypes, AKA subclasses). Normally, in Python, you want ... More on stackoverflow.com
🌐 stackoverflow.com
isinstance(x, list[list[int]]) doesn't work
Python doesn’t actually have generics, it’s just that the type hints have a generic-like syntax. But type hints aren’t an actual type - there’s no such thing as an instance of list[list[int]] in Python. More on reddit.com
🌐 r/learnpython
19
July 9, 2024
People also ask

When is it useful to use “isinstance()” in Python?
isinstance()” is useful when you want to perform different actions based on the type of an object or when you need to ensure that a variable contains a specific type of data, such as strings, dictionaries, or custom objects. “ isinstance() ” is useful when you want to perform different actions based on the type of an object or when you need to ensure that a variable contains a specific type of data, such as strings, dictionaries, or custom objects.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › isinstance() in python
Python isinstance(): Mastering Type Checking
What is the purpose of the “isinstance()” method in Python?
The “isinstance()” method is used to check if an object is an instance of a specific class or its subclasses. It helps in type-checking and ensures that your code works with the expected data types. The “ isinstance() ” method is used to check if an object is an instance of a specific class or its subclasses. It helps in type-checking and ensures that your code works with the expected data types.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › isinstance() in python
Python isinstance(): Mastering Type Checking
How does “isinstance()” differ from “type()” in Python?
isinstance()” checks if an object is an instance of a specific class or its subclasses and handles inheritance. “type()” returns the exact type of an object but does not handle inheritance. It only returns the exact type of the object. “ isinstance() ” checks if an object is an instance of a specific class or its subclasses and handles inheritance. “ type() ” returns the exact type of an object but does not handle inheritance. It only returns the exact type of the object.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › isinstance() in python
Python isinstance(): Mastering Type Checking
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.4 documentation
February 27, 2026 - The isinstance() built-in function is recommended for testing the type of an object, because it takes subclasses into account.
🌐
Medium
medium.com › @sim30217 › isinstance-dd8555e600fb
isinstance(). isinstance() is a built-in Python… | by Simsangcheol | Medium
March 23, 2023 - isinstance() is a built-in Python function that is used to check if an object is an instance of a specified class or a subclass of that
🌐
Python.org
discuss.python.org › python help
How to `isinstance` a typing type so that it works with static type checkers? - Python Help - Discussions on Python.org
January 25, 2024 - My code defines lots of typing types, and I need to isinstance lots of objects against them at runtime. Something like this: Type1 = list[int] Type2 = list[str] # etc. # get data from the outside, e.g. read from a file data = get_data() # NOT WORKING if isinstance(data, Type1): "do something" elif isinstance(data, Type2): "do something else" else: "etc."
Find elsewhere
🌐
Switowski
switowski.com › blog › type-vs-isinstance
type() vs. isinstance()
October 15, 2020 - But the following recommendations are still valid no matter which version of Python you are using. Speed is not the only difference between these two functions. There is actually an important distinction between how they work: type only returns the type of an object (its class). We can use it to check if variable is of a type str. isinstance checks if a given object (first parameter) is:
🌐
Real Python
realpython.com › what-does-isinstance-do-in-python
What Does isinstance() Do in Python? – Real Python
July 21, 2025 - Python’s isinstance() function helps you determine if an object is an instance of a specified class or its superclass, aiding in writing cleaner and more robust code. You use it to confirm that function parameters are of the expected types, ...
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › isinstance.html
isinstance — Python Reference (The Right Way) 0.1 documentation
>>> isinstance(u'foo', (basestring, str, unicode)) True >>> isinstance(u'foo', (basestring, str)) True >>> isinstance(u'foo', (basestring)) True >>> isinstance(u'foo', (str)) False
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › isinstance() in python
Python isinstance(): Mastering Type Checking
November 12, 2024 - Python's "isinstance()" method is an effective tool for type checking in the language. Its main objective is to determine whether an object belongs to that class or a subclass derived from it.
🌐
Vultr Docs
docs.vultr.com › python › built-in › isinstance
Python isinstance() - Check Type Membership | Vultr Docs
September 27, 2024 - The isinstance() function in Python is invaluable for ensuring type correctness in data handling and processing scenarios. By incorporating type checks using isinstance(), you improve the safety and predictability of your Python programs.
🌐
Sarthaks eConnect
sarthaks.com › 3486182 › python-isinstance-function
Python isinstance() Function
Join Sarthaks live online classes for 7-12, CBSE, State Board, JEE & NEET courses led by experienced expert teachers. Learn, Practice Test, Analyse and ace your exam.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Get and Check the Type of an Object in Python - nkmk note
April 22, 2025 - Use type() or isinstance() to check whether an object is of a specific type.
🌐
Programiz
programiz.com › python-programming › methods › built-in › isinstance
Python isinstance()
Become a certified Python programmer. Try Programiz PRO! ... The isinstance() function checks if the object (first argument) is an instance or subclass of classinfo class (second argument).
Top answer
1 of 8
1557

To summarize the contents of other (already good!) answers, isinstance caters for inheritance (an instance of a derived class is an instance of a base class, too), while checking for equality of type does not (it demands identity of types and rejects instances of subtypes, AKA subclasses).

Normally, in Python, you want your code to support inheritance, of course (since inheritance is so handy, it would be bad to stop code using yours from using it!), so isinstance is less bad than checking identity of types because it seamlessly supports inheritance.

It's not that isinstance is good, mind you—it's just less bad than checking equality of types. The normal, Pythonic, preferred solution is almost invariably "duck typing": try using the argument as if it was of a certain desired type, do it in a try/except statement catching all exceptions that could arise if the argument was not in fact of that type (or any other type nicely duck-mimicking it;-), and in the except clause, try something else (using the argument "as if" it was of some other type).

basestring is, however, quite a special case—a builtin type that exists only to let you use isinstance (both str and unicode subclass basestring). Strings are sequences (you could loop over them, index them, slice them, ...), but you generally want to treat them as "scalar" types—it's somewhat incovenient (but a reasonably frequent use case) to treat all kinds of strings (and maybe other scalar types, i.e., ones you can't loop on) one way, all containers (lists, sets, dicts, ...) in another way, and basestring plus isinstance helps you do that—the overall structure of this idiom is something like:

if isinstance(x, basestring)
  return treatasscalar(x)
try:
  return treatasiter(iter(x))
except TypeError:
  return treatasscalar(x)

You could say that basestring is an Abstract Base Class ("ABC")—it offers no concrete functionality to subclasses, but rather exists as a "marker", mainly for use with isinstance. The concept is obviously a growing one in Python, since PEP 3119, which introduces a generalization of it, was accepted and has been implemented starting with Python 2.6 and 3.0.

The PEP makes it clear that, while ABCs can often substitute for duck typing, there is generally no big pressure to do that (see here). ABCs as implemented in recent Python versions do however offer extra goodies: isinstance (and issubclass) can now mean more than just "[an instance of] a derived class" (in particular, any class can be "registered" with an ABC so that it will show as a subclass, and its instances as instances of the ABC); and ABCs can also offer extra convenience to actual subclasses in a very natural way via Template Method design pattern applications (see here and here [[part II]] for more on the TM DP, in general and specifically in Python, independent of ABCs).

For the underlying mechanics of ABC support as offered in Python 2.6, see here; for their 3.1 version, very similar, see here. In both versions, standard library module collections (that's the 3.1 version—for the very similar 2.6 version, see here) offers several useful ABCs.

For the purpose of this answer, the key thing to retain about ABCs (beyond an arguably more natural placement for TM DP functionality, compared to the classic Python alternative of mixin classes such as UserDict.DictMixin) is that they make isinstance (and issubclass) much more attractive and pervasive (in Python 2.6 and going forward) than they used to be (in 2.5 and before), and therefore, by contrast, make checking type equality an even worse practice in recent Python versions than it already used to be.

2 of 8
454

Here's an example where isinstance achieves something that type cannot:

class Vehicle:
    pass

class Truck(Vehicle):
    pass

In this case, a Truck object is a Vehicle, but you'll get this:

isinstance(Vehicle(), Vehicle)  # returns True
type(Vehicle()) == Vehicle      # returns True
isinstance(Truck(), Vehicle)    # returns True
type(Truck()) == Vehicle        # returns False, and this probably won't be what you want.

In other words, isinstance() is true for subclasses, too.

Also see: How to compare type of an object in Python?

🌐
Real Python
realpython.com › ref › builtin-functions › isinstance
isinstance() | Python’s Built-in Functions – Real Python
The built-in isinstance() function checks if an object is an instance of a specified class or a subclass thereof, returning a Boolean value. It’s a versatile tool for explicit type checking in Python, as it considers subclass relationships:
🌐
ZetCode
zetcode.com › python › isinstance-builtin
Python isinstance Function - Complete Guide
This comprehensive guide explores Python's isinstance function, which checks if an object is an instance of a class or tuple of classes.
🌐
Python Tutorial
techkubo.com › home › python isinstance: checking variable types
Python isinstance: Checking Variable Types - Python Tutorial
June 20, 2025 - Python Tutorial · Main Menu · TechKuboTechKubo · The isinstance function checks if a variable is an instance of a specified type or class. It returns True if the variable matches the type and False otherwise. isinstance is useful for ensuring data types, which is valuable in functions that ...
🌐
Devcuriosity
devcuriosity.com › manual › details › python-isinstance-function
Python - isinstance() function. Check if object is instance of a class
isinstance(object, class) is a built-in Python function that checks if an object is an instance of a specified class or a subclass of that class. It returns a boolean value.