Home / Python / Reference / Built-in functions

Python type() function

Return the type (class) of a value.

Syntax

type(obj)

Useful for exploring and debugging: when something behaves oddly, check its type first. To test a type in code, prefer isinstance.

Parameters

objany value

Return value

the type object, such as <class 'int'>

Example

Code

print(type(42))
print(type(3.14))
print(type("42"))
print(type([1, 2]), type({"a": 1}), type(None))
x = "7"
print(type(x) == str)

Output

<class 'int'>
<class 'float'>
<class 'str'>
<class 'list'> <class 'dict'> <class 'NoneType'>
True

Related

Learn it step by step in the free lesson Values, Variables & Numbers, with exercises that check your answers.