Python type() function Syntax
Syntax: type(object, bases, dict)
Parameters :
- object: Required. If only one parameter is specified, the type() function returns the type of this object
- bases : tuple of classes from which the current class derives. Later corresponds to the __bases__ attribute.
- dict : a dictionary that holds the namespaces for the class. Later corresponds to the __dict__ attribute.
Return: returns a new type class or essentially a metaclass.
How type() Function Works in Python?
In the given example, we are printing the type of variable x. We will determine the type of an object in Python.
Python3
x = 10 print ( type (x)) |
<class 'int'>
type() function in Python
The type() function is mostly used for debugging purposes. Two different types of arguments can be passed to type() function, single and three arguments. If a single argument type(obj) is passed, it returns the type of the given object. If three argument types (object, bases, dict) are passed, it returns a new type object.