作者StubbornLin (Victor)
看板Python
标题Re: [问题] for x in list 的 x
时间Sun Oct 19 15:39:03 2008
※ 引述《bobhsiao (㊣小臃肿㊣)》之铭言:
: list = [1, 2, 3, 4, 5]
: for x in list:
: x = 0
: for x in list:
: print x,
: 执行结果: 1 2 3 4 5
: ----------------------------
: 我的问题是: 有没有方法可以用 for loop 去修改 list 内的值?
用i去存取就可以
for i, x in enumerate(list):
list[i] = x + 1
--
易记学 程式设计教学
http://ez2learn.com/
易记学 程式设计讨论区
http://forum.ez2learn.com
VICTOR's 个人Blog
http://blog.ez2learn.com/
财报分析王
http://victorlin.serveftp.org/stock/
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.170.95.116
1F:推 bobhsiao:Tks 10/19 15:41
2F:推 bizkit:there is also range() and len() 10/19 22:22