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.

CategoryBuilt-in Functions
KindBuilt-in Function
Python Versionall

📝 Syntax

type(object)
type(name, bases, dict)

⚙️ Parameters

object RequiredOne-arg form: the object whose type is queried.
name RequiredThree-arg form: the class name (string); mutually exclusive with the one-arg form.
bases RequiredThree-arg form: a tuple of base classes.
dict RequiredThree-arg form: the class namespace dict (attributes/methods).

Returns:One-arg form: the object's type. Three-arg form: a newly created class.

💥 Raises

▶ Example

Edit the code, press Run, and see the result in the output panel:

Output:

int
10
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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏