Python type() function

Python type() function returns the type of given object. Or simply find the variable types whether it is int,string, list,dictionary,….

Python type() function Syntax:

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

Parameters:

name : name of class, which later corresponds to the __name__ attribute of the class.
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.

Examples:

1. Find data type of given object in Python:

carname= 'Honda' print(type(carname)

Output:

2. Verify the type of object belongs string,int,list, tuple or dictionary.

Create a variable:

test='r2schools'

Now test variable type in Python using below methods:

print(type(test) is str) True print(type(test) is int) False print(type(test) is list) False print(type(test) is tuple) False print(type(test) is dict) False