【Python开发】查看数据类型

import types  
  
aaa = 0  
print type(aaa)  
if type(aaa) is types.IntType:  
    print "the type of aaa is int"  
if isinstance(aaa,int):  
    print "the type of aaa is int"  
  
bbb = 'hello'  
print type(bbb)  
if type(bbb) is types.StringType:  
    print "the type of bbb is string"  
if isinstance(bbb,str):  
    print "the type of bbb is string"  
  
#if the type is NoneType,the isinstance does not work  
#we should judge the NoneType like below  
#if row is None  
#if type(row) is types.NoneType  
  
#In my opinion,use the types to judge the type of a param is convinient

posted @ 2016-09-24 21:59  ZhangPYi  阅读(361)  评论(0编辑  收藏  举报