Runtime inspection
Inspecting values during debugging or logging.
Python · Class
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__.
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__.
type(object)
type(name, bases, dict)| Name | Type | Description |
|---|---|---|
object | object | The object whose runtime type is requested; alternatively, the three-argument form accepts a name, base classes, and an attribute namespace for creating a type. |
With one argument, returns the object's type object; the three-argument form creates a new 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.
Inspecting values during debugging or logging.
Comparing a value with an exact built-in class.
Creating classes dynamically from a name, bases, and namespace.
object.__class__isinstance()issubclass()types