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
| Name | Type | Description |
|---|---|---|
| object | object | Required for the inspection form; alternative to class-construction arguments. |
| name | str | Class name; required for three-argument form. |
| bases | tuple of types | Base classes; required for three-argument form. |
| dict | dict | Namespace; required for three-argument form. |
| kwargs | keyword arguments | Additional 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)