python类型判断
2015-11-18 14:19
671 查看
python语言提供了type函数来判断传入数据的类型,我们可以利用函数来做类型判断。
例如:
如果不知道类型是什么名字,直接type出来。
例如:
class A: a=1 if type(5) == int: print "This is int" if type("xxx") == str: print "This is str" if type(['a','b']) == list: print "This is list" if type({'a':1,'b':2}) == dict: print "This is dict" This is int This is str This is list This is dict
如果不知道类型是什么名字,直接type出来。
class A: pass b=A() print type(A) print type(b) 结果: <type 'classobj'> <type 'instance'>
相关文章推荐
- Python——赋值语句
- python和numpy的版本、安装位置
- python 线程,GIL 和 ctypes
- python 第二天 条件语句的使用
- print函数输出(python)
- 机器学习实战python环境搭建以及numpy和matplotlib安装遇到的各种问题(一)
- Python变量类型
- python向mysql插入特殊字符
- python argparse的例子
- Python中的命令行解析工具介绍
- Python 类 setattr、getattr、hasattr 的使用
- 处理json注释 之 小搞python正则表达式
- Python2.x与3.x版本区别
- To pack your python scripts to EXE by using PyInstaller3.0
- Python 面向对象(初级篇)
- python--自动删除文件
- python--自动删除文件
- Python 的开发环境
- 第一个python 实例--监控服务器CPU
- 第一个python实例--监控cpu