码迷,mamicode.com
首页 > 编程语言 > 详细

Python学习--判断变量的数据类型

时间:2014-09-04 01:33:27      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   数据   div   sp   log   

 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 work
18 #we should judge the NoneType like below
19 #if row is None
20 #if type(row) is types.NoneType
21 
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学习--判断变量的数据类型

标签:style   blog   color   io   ar   数据   div   sp   log   

原文地址:http://www.cnblogs.com/feiling/p/3955135.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!