Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Class

type

type() returns an object's runtime type, or creates a new type when called with three arguments. Its one-argument result generally matches the object's __class__.

How it works

Call type() with one argument to inspect an object's runtime type. With three arguments, it dynamically creates a new type from a name, base classes, and an attribute namespace; the one-argument form is generally equivalent to accessing object.__class__.

Syntax

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

Parameters

NameTypeDescription
objectobjectThe object whose runtime type is requested; alternatively, the three-argument form accepts a name, base classes, and an attribute namespace for creating a type.

Returns

With one argument, returns the object's type object; the three-argument form creates a new type.

Key points

  • Use type(value) to obtain the runtime type of value.
  • The result can be compared with a class object such as int or str.
  • type() is available directly; no import is needed.
  • A type object represents an object type and does not add special operations through type() itself.

Common mistakes

  • For inspection, type() returns a type object; it is generally the same object available through object.__class__.
  • The one-argument form reports an object's type rather than testing whether it belongs to a class hierarchy.

Example: Inspect an object's type

value = 42
print(type(value))
print(type(value) is int)

Displays the runtime type of an integer and checks whether that type object is exactly int.

When to use it

Runtime inspection

Inspecting values during debugging or logging.

Exact type checks

Comparing a value with an exact built-in class.

Dynamic class creation

Creating classes dynamically from a name, bases, and namespace.

  • object.__class__
  • isinstance()
  • issubclass()
  • types

Source: Built-in functions. Checked 2026-10-15.