How to Check a Value's Type in Python with isinstance
isinstance(value, str) answers one question: is this value a string? It returns True or False, it can test for several types at once, and it has one surprise worth knowing before you rely on it: True and False count as integers.
Syntax
isinstance(<value>, <type>)
isinstance(<value>, (<type>, <type>))
isinstance(<value>, <type> | <type>)
| Part | What it does |
|---|---|
<value> | The value to test: a variable, a literal or any expression. |
<type> | A type such as str, int, float, list or dict, written as a name, without quotes. |
(<type>, <type>) | A tuple of types. The result is True when the value is an instance of any of them. |
<type> | <type> | A union of types, which works the same way as the tuple. |
The Python documentation for isinstance(): "Return True if the object argument is an instance of the classinfo argument, or of a (direct, indirect, or virtual) subclass thereof. If object is not an object of the given type, the function always returns False."
The Example
The example tests eight values: the string "Ada", the number 42, the number 3.5 against int, a list, a dictionary, None against dict, 3.5 against the tuple (int, float), and True against int. Each line prints True or False.
Prerequisites
- uv and Python. This guide uses uv 0.13.10 with Python 3.15.2.
Step 1: Write the Code
Create a file named main.py:

print(isinstance("Ada", str))
print(isinstance(42, int))
print(isinstance(3.5, int))
print(isinstance(["a", "b"], list))
print(isinstance({"name": "Ada"}, dict))
print(isinstance(None, dict))
print(isinstance(3.5, (int, float)))
print(isinstance(True, int))
Step 2: Run It
uv run python main.py
uv run python main.py runs the file with the Python that uv manages.
True
True
False
True
True
False
True
True

The command is the same in zsh, bash and PowerShell.
What Happened
- The first two lines are
True."Ada"is astr, and42is anint. isinstance(3.5, int)isFalse.3.5is afloat, and afloatisn't anint, though both are numbers.- The list and the dictionary passed, and
Nonedidn't. A missing value fails a type check, so a check likeisinstance(value, dict)also catchesNonebefore your code reads the value. - The tuple
(int, float)accepted3.5, becausefloatis one of the types in it. isinstance(True, int)printedTrue. The documentation for bool says: "The bool class is a subclass of int". A check for a whole number letsTrueandFalsethrough.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Writing the type's name in quotes: isinstance(x, "str") | TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union | Write the type itself: isinstance(x, str) |
Testing for a list of strings with isinstance(x, list[str]) | TypeError: isinstance() argument 2 cannot be a parameterized generic | Test isinstance(x, list), then check the items |
Testing a number with isinstance(x, int) when True and False must not pass | isinstance(True, int) is True | isinstance(x, int) and not isinstance(x, bool) |
Expecting 10.0 to pass a check for int | isinstance(10.0, int) is False | Use (int, float) when both are fine |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union | The second argument is text or another value, not a type | Pass a type, a tuple of types, or a union such as int | float |
TypeError: isinstance() argument 2 cannot be a parameterized generic | The second argument is a type hint such as list[str] | Pass the plain type, such as list |
True got through a check for numbers | bool is a subclass of int | Rule out bool first |
FAQ
What's the difference between isinstance() and type()?
type(value) gives the value's exact type, while isinstance() also accepts subclasses. type(True) == int is False, but isinstance(True, int) is True.
Can isinstance() check for several types at once?
Yes. Pass a tuple, isinstance(x, (int, float)), or a union, isinstance(x, int | float). Both returned True for 3.
How do I check for None?
value is None. PEP 8, Python's style guide, says: "Comparisons to singletons like None should always be done with is or is not, never the equality operators."
Which types does data from json.loads have?
json.loads returns str, int, float, bool, None, list and dict, so isinstance() can check each value it gives you before your code uses it.
Conclusion
isinstance(value, type) tells you whether a value has the type your code expects. Pass a tuple or a union for several types, write the type without quotes, and rule out bool when only real numbers should pass.
Additional Resources
- isinstance(), in the Python documentation.
- Boolean Type - bool, on how
TrueandFalserelate toint.
