python数组遍历三种实用方法
- 2020 年 1 月 9 日
- 筆記
>>> 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首选) 1) 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)