Python type() Function
Python type() Function
The type() function in Python returns the type of an object. The return value is a type object and generally the same object as returned by object.__class__.
Syntax
class type(object)
or
class type(name, bases, dict)
Parameter
object- If only one parameter is specified, the type() function returns the type of this object.
base- It is an optional parameter that specifies the base classes.
dict- This parameter specifies the namespace with the definition for the class.
Return
This function returns the type of an object.
Example 1
# Python program explaining # the type() function x = ('Monday', 'Tuesday', 'Wednesday','Thursday') y = "Hello World" z = 383 val1 = type(x) val2 = type(y) val3 = type(z) print(val1) print(val2) print(val3)
Output
<class 'tuple'> <class 'str'> <class 'int'>
Example 2
# Python program explaining # the type() function #printing the type for list print(type([]) is list) print(type([]) is not list) #printing the type for tuple print(type(()) is tuple) #printing the type for dict print(type({}) is dict) print(type({}) is not list)
Output
True False True True True