源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Python数组遍历的简单实现方法小结

  • 时间:2022-09-23 05:50 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Python数组遍历的简单实现方法小结
本文实例总结了Python数组遍历的简单实现方法。分享给大家供大家参考,具体如下:
 >>> os.__file__.split('\\')
['E:', 'Python', 'Python25', 'lib', 'os.pyc']
>>> os.path.split(os.__file__)
('E:\\Python\\Python25\\lib', 'os.pyc')

var myArr:Array = new Array("one", "two", "three");
var myStr:String = myArr.join(" and ");
trace(myArr); // one,two,three
trace(myStr); // one and two and three

1) 将每个id的属性值插入数组,Aarry.join(",") 成字符串,保存到一个txt里,或者数据库表里。(txt首选) 2) python直接解析 split(",") 成数组,索引+1是文件名,值是数据库id,读取数据库, 用enumerate函数,遍历数组,生成xml。(首选) 在Python中,我们习惯这样遍历:
for item in sequence:
process(item)

这样遍历取不到item的序号i,所有就有了下面的遍历方法:
for index in range(len(sequence)):
process(sequence[index])

其实,如果你了解内置的enumerate函数,还可以这样写:
for index, item in enumerate(sequence):
process(index, item)

更多关于Python相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/663.htm]Python数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/648.htm]Python Socket编程技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/642.htm]Python函数使用技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/636.htm]Python字符串操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/520.htm]Python入门与进阶经典教程[/url]》及《[url=http://www.1sucai.cn/Special/516.htm]Python文件与目录操作技巧汇总[/url]》 希望本文所述对大家Python程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部