Python Function Reference

type

Get the type of an object.

Python 3.13
type(object)
object
The object whose type to get.
Any

Return value

The class of the object, such as <class 'int'>.

Examples

Type of an integer

Python 3.13
print(type(123))
<class 'int'>

Comparing a type with a class

Python 3.13
print(type('hi') == str)
True

Details

To check a type, isinstance is usually better because it takes subclasses into account. Called with three arguments, type(name, bases, dict) creates a new class.

See also

Where to learn