首页 > 代码库 > Python学习--判断变量的数据类型
Python学习--判断变量的数据类型
1 import types 2 3 aaa = 0 4 print type(aaa) 5 if type(aaa) is types.IntType: 6 print "the type of aaa is int" 7 if isinstance(aaa,int): 8 print "the type of aaa is int" 9 10 bbb = ‘hello‘11 print type(bbb)12 if type(bbb) is types.StringType:13 print "the type of bbb is string"14 if isinstance(bbb,str):15 print "the type of bbb is string"16 17 #if the type is NoneType,the isinstance does not work18 #we should judge the NoneType like below19 #if row is None20 #if type(row) is types.NoneType21 22 #In my opinion,use the types to judge the type of a param is convinient<span style="font-family:Arial;background-color: rgb(255, 255, 255);">, use the isinstance to judge whether a instance is a type of a class or not</span>
Python学习--判断变量的数据类型
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。