🔵 🔵 🔵


Primary

၊၊||၊|။

type() ⚬ᵖʸ|Documentation|1st|20251021164022-00-⌔

Built-in Functions — Python 3 documentation#type

class type(object,/)

class type(name, bases, dict,/, ﹡﹡kwargs)

With one argument, return the type of an object. The return value is a type object and generally the same object as returned by object.__class__.

The isinstance() built-in function is recommended for testing the type of an object, because it takes subclasses into account.

With three arguments, return a new type object. This is essentially a dynamic form of the class statement. The name string is the class name and becomes the __name__ attribute. The bases tuple contains the base classes and becomes the __bases__ attribute; if empty, object, the ultimate base of all classes, is added. The dict dictionary contains attribute and method definitions for the class body; it may be copied or wrapped before becoming the __dict__ attribute. The following two statements create identical type objects:

>>> class X:
...     a = 1
...
>>> X = type('X', (), dict(a=1))

See also:

  • Documentation on attributes and methods on classes.
  • Type Objects

Keyword arguments provided to the three argument form are passed to the appropriate metaclass machinery (usually __init_subclass__()) in the same way that keywords in a class definition (besides metaclass) would.

See also Customizing class creation.

Changed in version 3.6: Subclasses of type which don’t override type.__new__ may no longer use the one-argument form to get the type of an object.

Printed 2026-06-28.

(echo:: @ )

Link to original

Secondary

• • •