array

class array.array(typecode[,initializer])

参数:typecode

typecode    对应的C类型    对应的Python类型
'b'       signed char     int
'B'       unsigned char       int
'u'                  Py_UNICODE           Unicode character
'h'                 signed short             int
'H'              unsigned short            int
'i'                       signed int           int
'I'              unsigned int                int
'l'                  signed long              int
'L'               unsigned long            int
'q'            signed long long           int
'Q'          unsigned long long         int
'f'             float                          float
'd'           double                         float

参数:initializer 必须是list或bytes-like对象,或可迭代对象(对于字符串,bytecode只能是'u')

模块属性
array.typecodes 返回所有可用typecode

对象属性方法
array.typecode 返回对象的typecode
array.itemsize 返回数组单个元素大小(字节)
array.append(x) 尾部添加元素
array.buffer_info() 返回tupe(address,length)数组的内存地址和元素个数
array.byteswap() 调换字节序,只支持元素大小是1,2,4,8字节的数组
array.count(x) 统计x在数组的个数
array.extend(iterable) 添加元素从iterable
array.frombytes(s) 添加元素从bytes
array.fromfile(f,n)添加n个元素从文件对象f
array.fromlist(list) 添加对象从list
array.fromstring() 废弃,3.2以后是frombytes()
array.fromunicode(s) 添加对象从一个字符串,数组必须是'u',对于其它类型的数组则使用frombytes('字符串'.encode(编码))添加
array.index(x) 返回x的索引值
array.insert(i,x) 插入x到位置i
array.pop([i]) 从位置i移除元素
array.remove(x) 移除元素x
array.reverse() 翻转数组
array.tobytes() 转换数组为bytes
array.tofile(f) 转换数组为文件对象
array.tolist() 转换数组为列表
array.tostring() 废弃,使用tobytes
array.tounicode() 转换数组为字符串

posted on 2016-11-02 21:06  eaxebx  阅读(201)  评论(0编辑  收藏  举报

导航