[Tutor] For loop breaking string methods
C M Caine
cmcaine at googlemail.com
Mon Apr 26 21:38:17 CEST 2010
Why does this not work:
>>> L = [' foo ','bar ']
>>> for i in L:
i = i.strip()
[' foo ', 'bar ']
>>> # note the leading whitespace that has not been removed.
But this does:
>>> L = [i.strip() for i in L]
What other strange behaviour should I expect from for loops?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor