type() Type or dynamic class
Last updated: 2026-09-22
type() Type or dynamic class
type(obj) returns the object's type; type(name, bases, dict) dynamically creates a new class.
| Category | Built-in Functions |
|---|---|
| Kind | Built-in Function |
| Python Version | all |
📝 Syntax
type(object)
type(name, bases, dict)
⚙️ Parameters
| object Required | One-arg form: the object whose type is queried. |
|---|---|
| name Required | Three-arg form: the class name (string); mutually exclusive with the one-arg form. |
| bases Required | Three-arg form: a tuple of base classes. |
| dict Required | Three-arg form: the class namespace dict (attributes/methods). |
Returns:One-arg form: the object's type. Three-arg form: a newly created class.
💥 Raises
TypeError— Raised when name is not a string in the three-arg form.
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
int
10
🏷️ Related Built-in Functions
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat does type(42) return?
AIt returns — the one-argument form returns the type of the object.
QWhat is the difference between type(x) == int and isinstance(x, int)?
Aisinstance recognizes subclasses: bool is a subclass of int, so isinstance(True, int) is True while type(True) == int is False; in general isinstance is safer.
QWhat is the three-argument form type(name, bases, dict) for?
AIt dynamically creates a new class: type('MyClass', (object,), {'x': 10}) is equivalent to class MyClass(object): x = 10 — the basis of metaclass programming.
QHow do I get the name of an object's type?
AUse type(obj).__name__; for example type(42).__name__ returns 'int'. print(type(x)) shows the form.