How to Check the Type of a Value in Python with type()
Python decides what kind of value a variable holds, a whole number, a decimal, some text or a list, and the kind decides what you can do with it. When a value doesn't behave the way you expect, ask Python what it is with type(). This guide does that on Python 3.15.2.
Syntax
type(<value>)
| Part | What it means |
|---|---|
<value> | Any value, variable or expression |
type(...) | Returns the value's type, such as int. Printed, it shows as <class 'int'> |
The Python documentation says: "With one argument, return the type of an object." In Python, a type is a class, which is why it prints with the word class.
The Example
A script asks for the type of four values: a whole number, a decimal, a piece of text and a list.
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
print(type(42))
print(type(3.5))
print(type("hello"))
print(type([1, 2, 3]))
![The type_check.py script in a macOS-style code window: print of type(42), type(3.5), type("hello") and type([1, 2, 3]).](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/programming/python/2026/python-type-01-code.webp)
Step 2: Run It
uv run python type_check.py
<class 'int'>
<class 'float'>
<class 'str'>
<class 'list'>

42 is an int (a whole number), 3.5 a float (a decimal), "hello" a str (text) and [1, 2, 3] a list. The command works unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
type(42) == "int" | It printed False: a type isn't text | type(42) == int, which printed True |
Testing a type with == when subclasses count | type(True) == int printed False, though True is a kind of int | isinstance(True, int), which printed True |
FAQ
How do I get just the name, without <class ...>?
Read the type's __name__: type(42).__name__ printed int.
Should I use type() or isinstance() in an if?
isinstance(). The documentation says: "The isinstance() built-in function is recommended for testing the type of an object, because it takes subclasses into account." type() is best for finding out what a value is.
Conclusion
type() reported int for 42, float for 3.5, str for "hello" and list for [1, 2, 3]. To test a type in code, isinstance() also accepts subclasses.
Additional Resources
- type() — the built-in function.
- isinstance() — testing whether a value is of a type.
- Built-in types —
int,float,str,listand the rest.
