Python - Data Type Type object

Introduction

The type object, returned by the type built-in function, is an object that gives the type of another object.

Demo

L=[1,2,3]
# In Python 2.X: # from  w ww. j a v  a  2  s  .  c  o  m
print( type(L) )                         # Types: type of L is list type object 
print( type(type(L)) )                   # Even types are objects 

# In Python 3.X: 
print( type(L) )                         # 3.X: types are classes, and vice versa 
print( type(type(L)) )                   # See Chapter 32 for more on class types

Result

The type object checks the types of the objects it processes.

if type(L) == type([]):         # Type testing, if you must... 
   print('yes') 

if type(L) == list:             # Using the type name 
   print('yes') 

if isinstance(L, list):         # Object-oriented tests 
   print('yes') 

Related Topic