python 遍历_python数组遍历三种实用方法

python数组遍历三种实用方法

发布时间:2019-09-07 08:11:32编辑:auto阅读(864)

>>> 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)

关键字:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值