Function Details: type

Description


Returns the type of an object, or create a new type object.


Extended Description


The type() function has two distinct behaviors: 1) With one argument, it returns the type of the object. 2) With three arguments, it creates a new type object (a class). It's the metaclass of all classes in Python, and can be used to dynamically create classes. When creating a new type, the first argument is the class name, the second is a tuple of base classes, and the third is a dictionary defining the namespace of the class.


Read More about type from Python Documentation

Function Signature


type(object: Any) -> type
type(name: str, bases: Tuple[type, ...], dict: Dict[str, Any]) -> Type

Module: builtins

Class: type

Parameters



Parameter List


  • object: Any
  • bases: Optional[Tuple[type, ...]]
  • dict: Optional[Dict[str, Any]]

Return


With one argument, returns the type of the object. With three arguments, returns a new type object.


Return Type


Union[type, Type]

Output

Explanation

These examples show how type() is used to get the type of various objects.