Python内建函数type(object),import types>>>type(1)=types.IntType True>>>type()=types.StringType True
type(x)is types.IntType#判断是否int 类型 type(x)is types.StringType#是否string类型 超级恶心的模式,
import types aaa=0 print type(aaa)if type(aaa)is types.IntType:print"the type of aaa is int"if
from schematics.models import Model from schematics.types import StringType,IntType class
if type(var)in[types.IntType,types.LongType]: body else: body 注意IntType和LongType,因为1是IntType,
types-example-1.py import types def check(object):print object,if type(object)is types.IntType:
types)里面的函数(IntType),都需要先查询模块,然后再查询模块内部的函数。所以,从性能角度来讲,可以使用
if type(num)=type(0):#pass#对象身份比较:#if type(num)is types.IntType:pass#减少查询次数#import
1-19 inttype using morecompact type requiresless memory would faster.More compact types include