当前位置: 移动技术网 > IT编程>脚本编程>Python > Python程序设计入门(2)变量类型简介

Python程序设计入门(2)变量类型简介

2019年03月29日  | 移动技术网IT编程  | 我要评论

比蒙传,烽火纪元,阿丁新浪博客

通常来说,python的变量/数据类型非常多,但是它是不需要用户指定的,因为有些是根据部份系统函数生成另外一些是自动根据变量的值识别的,这些数据类型常量在class types定义,所以使用时需要 import types如:

复制代码 代码如下:
import types
a = [1,2,3]
if type(a) is types.listtype:
    print a
else:
    print 'not list'

python的具体变量/数据类型如下:

nonetype
none 类型

typetype
type对象自身

booleantype
布尔类型

inttype
整数类型

longtype
长整型

floattype
浮点类型

complextype
复数类型(如1.0j 如果不支持的情况下将不会被定义此类型)

stringtype
字符串类型 (e.g. 'spam').

unicodetype
unicode 字符串 (e.g. u'spam' 如果不支持的情况下将不会被定义此类型)

tupletype
元组类型

listtype
链表数组类型

dicttype
哈希数组类型(词典数组)

dictionarytype
上面的全称

functiontype
函数类型

lambdatype
函数类型备用名称

generatortype
迭代器对象,通过调用函数发生器产生的。

codetype
对于代码对象的类型,如由 compile() 返回。

classtype
对象类型

instancetype
对象实例类型

methodtype
对象的方法

unboundmethodtype
methodtype备用名称。

builtinfunctiontype
内置的函数类型,如 len() or sys.exit().

builtinmethodtype
builtinfunction的备用名称

moduletype
模块类型

filetype
如sys.stdout打开的文件类型的对象。

xrangetype
xrange() 返回的范围选择对象

slicetype
slice() 返回的对象

ellipsistype
省略的类型。

tracebacktype
如 sys.exc_traceback 返回的对象类型

frametype
一种回溯对象如 tb.tb_frame

buffertype
buffer()函数返回的类型

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网