【Python】判断一个变量的数据类型的两种方法

来源:互联网 发布:mac打不开exe文件夹 编辑:程序博客网 时间:2024/05/22 14:48

法1:  

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

法2: 

import typestype(x) == type(1)  # 是否 int 类型type(x) in (type('u') , type(''))# 是否string, unicode类型



源地址:http://blog.sina.com.cn/s/blog_77b69fcb0101qnhw.html

0 0
原创粉丝点击