Built-in Functions and Types

type()

Inspect the actual type of an object or construct a class dynamically. The one-argument form does not test subclass membership; use isinstance for that. The three-argument form takes a name, base tuple and namespace dictionary; class creation may invoke metaclass and base-class hooks. Unlike the class statement, this form does not call __prepare__ itself. Additional keywords are passed to class creation and must be supported by the relevant hooks.

Formal Syntax & Structure

python syntaxpython
type(object, /)type(name, bases, dict, /, **kwargs)

Parameters & Attributes

NameTypeDescription
objectobjectRequired for the inspection form; alternative to class-construction arguments.
namestrClass name; required for three-argument form.
basestuple of typesBase classes; required for three-argument form.
dictdictNamespace; required for three-argument form.
kwargskeyword argumentsAdditional class creation options.

Return Value

type

Actual type or dynamically created class object.

Working Example

Example Snippetpython
Badge = type("Badge", (), {"label": "ready"})item = Badge()print(type(item).__name__)print(item.label)print(isinstance(True, int), type(True) is int)
Python Reference