Python中的数组
来源:互联网 发布:mac怎么使用投影仪 编辑:程序博客网 时间:2024/06/03 18:38
1 数组的创建:
涉及的module: array
An array object is similar to a list except that it can hold only certain types of simple data and only one type at any given time. when you create an array object,you specify which type of data it will hold:
>>> import array
>>> z=array.array('B')
>>> z.append(5)
>>> z
array('B', [5])
>>> z[0]
5
>>> q= array.array('i',[5,10,20])
>>> q
array('i', [5, 10, 20])
>>> q[0]
5
数组支持的数据类型:
求数组的长度:
arrayname.itemsize;
>>> q.itemsize
4
数组和list 之间转换:
数组转换为list:toList(): converts the array to an ordinary list
>>> q.tolist()
[5, 10, 20]
将一个list添加到数组的末尾:
>>> q
array('i', [5, 10, 20])
>>> q.fromlist([3,4])
>>> q
array('i', [5, 10, 20, 3, 4])
array 和string之间的相互转换:
tostring():onvert an array to a sequence of bytes using the tostring() methond.
fromstring():taking a string of bytes and converting them to values for the array
数组和文件之间的互操作:
tofile(file):convert the array to a sequence of bytes and writes the resulting bytes to a file you pass in
fromfiles(file,count): reads the specifiled number of items in from a file object and appends them to the array.
- Python中的数组
- Python中的数组
- Python中的Numpy数组
- python中的二维数组
- python 中的 数组 矩阵 列表
- python 中的 数组 矩阵 列表
- Python:数组中的逆序对
- python 刷题:二维数组中的查找
- python读取二进制文件中的浮点数数组
- 牛客网 二维数组中的查找python实现
- python中的数组类型及特点
- Python: NumPy中的多维数组ndarray
- Python: NumPy中的多维数组ndarray
- c语言模拟perl python中的数组负数索引
- f2py::演示Fortran二维数组在python中的使用示例
- Python:将文件中的数据读入到数组中
- Python中的二维数组(list与numpy.array)
- python列表的嵌套,嵌套循环,numpy中的数组
- android 如何隐藏4.0以上系统下面的3按个虚拟按键?
- centOS修改机器名 hosts
- 移动开发网
- Configuring SIP Call-Transfer Features
- SQL: group by 要聚合的 是非数值字段?
- Python中的数组
- 宣布: Windows Azure SQL 数据库的的新系统视图
- android网络类型 wap代理设置
- linux一句话精彩回答
- Oracle Workflow Queries
- PHP常用的文件操作函数集锦
- Unity3D(1)——发布设置
- 朝花夕拾-3-TLB & cache
- Intel's KVM official dev site