Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

type()

Returns the actual type of a runtime object.

Version: Python 3.14; repository image, production runtime not attested

Syntax

type(object, /)
type(name, bases, namespace, /, **kwargs)

Returns the actual type of a runtime object.

An exact type comparison distinguishes a Boolean from an integer although the Boolean type inherits from the integer type.

One argument returns the actual runtime class. True has exact type bool, not int, although isinstance(True, int) succeeds through inheritance. With three positional arguments type instead constructs a class from its name, a tuple of bases and a namespace dictionary. The new class is itself an object.

Flag = type("Flag", (object,), {"active": True})
assert type(Flag()) is Flag and Flag().active is True
assert type(True) is bool and isinstance(True, int)

Examples

print(type(True) is bool)
print(type(True) is int, isinstance(True, int))

Result

True
False True

One argument returns the actual runtime class. True has exact type bool, not int, although isinstance(True, int) succeeds through inheritance. With three positional arguments type instead constructs a class from its name, a tuple of bases and a namespace dictionary. The new class is itself an object.

Sources