type
import types
class Animal():
pass
i = 5;
string = 'abc'
ustring = u'xyz'
animal = Animal()
print type(i)
print type(string)
print type(ustring)
print type(animal)
print type(5)
print type('abc')
print type(u'xyz')
print type(Animal())
print type(None)
print type(int)
print type(str)
print type(unicode)
print type(Animal)
print type(type(i))
print type(5) == types.IntType
print type('abc') == types.StringType
print type(u'xyz') == types.UnicodeType
print type(None) == types.NoneType
print type(int) == types.TypeType
print type(str) == types.TypeType
output:
<type 'int'>
<type 'str'>
<type 'unicode'>
<type 'instance'>
<type 'int'>
<type 'str'>
<type 'unicode'>
<type 'instance'>
<type 'NoneType'>
<type 'type'>
<type 'type'>
<type 'type'>
<type 'classobj'>
<type 'type'>
True
True
True
True
True
True
总结:
type函数返回变量或者对象的type类型
type类型定义在types模块中,types模块中预定义了内置类型
type(内置类型)返回值为type类型
类的实例返回类型为instance,类返回类型为classobj