浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Python类型:types模块 - ArcherXu - 博客园

Python类型:types模块

Python内建函数type(object),用于返回当前object对象的类型。例如:

>>> type(1)
<type 'int'>
>>> type("1")
<type 'str'>

types模块定义了python中所有的类型,包括NoneType, TypeType, ObjectType....

types模块所在的位置为{%PYTHONPATH%\lib\types.py}.

实现方法很简单,把对应的类型赋值给变量:

复制代码
NoneType = type(None)
TypeType = type
ObjectType = object

IntType = int
LongType = long
FloatType = float
BooleanType = bool

StringType = str
复制代码

因此,在我们的代码中可以这样来使用:

>>> import types
>>> type(1)==types.IntType
True
>>> type("1")==types.StringType
True
posted on 2013-01-04 01:27  lexus  阅读(446)  评论(0编辑  收藏  举报