当前位置:编程学习 > 网站相关 >>

python中如何判断一个变量的数据类型?(原创)

import types
type(x) is types.IntType # 判断是否int 类型
type(x) is types.StringType #是否string类型
.........

 

--------------------------------------------------------

超级恶心的模式,不用记住types.StringType

import types
type(x) == types(1) # 判断是否int 类型
type(x) == type('a') #是否string类型

 

补充:Web开发 , Python ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,