数组并不是Python中内置的标配数据结构,不过拥有array模块我们也可以在Python中使用数组结构,下面我们就来详解详解Python中的array数组模块相关使用
>>> import array#定义了一种序列数据结构
>>> help(array)
#创建数组,相当于初始化一个数组,如:d={},k=[]等等
array(typecode [, initializer]) -- create a new array
#a=array.array(‘c‘),决定着下面操作的是字符,并是单个字符
#a=array.array(‘i‘),决定着下面操作的是整数
| Attributes:
|
| typecode -- the typecode character used to create the array
| itemsize -- the length in bytes of one array item
初始化
array实例化可以提供一个参数来描述允许那种数据类型,还可以有一个初始的数据序列存储在数组中。
import array
import binascii
s = 'This is the array.'
a = array.array('c', s)
print 'As string:', s
print 'As array :', a
print 'As hex :', binascii.hexlify(a)
数组配置为包含一个字节序列,