What is the type function in Python?

The type() function in Python returns the data type of the object passed to it as an argument. This function is very useful in the debugging process​.

svg viewer

Syntax

The syntax of the type() function in Python is:

svg viewer

Code

The code snippet below illustrates the usage of the type() function in Python:

print(type([]))
print(type(()))
print(type({}))
print "------------"
print (type([1,2,3]))
print (type((1,2,3)))
print (type({"A": "Apple", "B": "Banana"}))
print "------------"
print (type("Educative"))
print (type(34))
print (type(3.142))
print (type(True))
print "------------"
### Comparing data types
a = 3
b = "Hello"
c = 3.143
d = "Educative"
if type(a) == type(c):
print ("Types match")
else:
print ("Types don't match")
if type(b) == type(d):
print ("Types match")

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved