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首選) 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)
相關文章
相關標籤/搜索