python中数组的使用
1、python 数组支持所有list操作,包括 .pop、.insert 和 .extend。另外,数组还提供从文件,读取和存入文件的更快的方法,列如如 .frombytes 和 .tofile,如下所示我们定义一个数组from array import arrayarr=array('d',(a for a in range(5)))print(arr)

3、在步骤1基础上我们来像数组中添加一个元素from array import arrayarr=array('d',(a for a in range(5)))print(arr)arr.append('ssss')我们会发现控制台报错,这是因为arr的类型已经被定义为浮点类型了

5、我们还可以把该浮点数组写到一个文件from array import arrayarr=array('d',(a for a in range(5)))print(arr)arr.append(111)print(arr)fp = open('arr.txt', 'wb')arr.tofile(fp)fp.close()如下图所示运行它 我们目录文件有arr.txt

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:51
阅读量:34
阅读量:69
阅读量:78
阅读量:61