[Tutor] range/for list change behavior
parrisdc at gmail.com
Tue Sep 30 04:33:56 CEST 2008
After a rather long (and unfortunate) break from tinkering with Python, I am
back at it. I am working through the book Learning Python (based on 2.2/2.3
- I use 2.5), and in the chapter on while/for loops, ran across the
>>> L = [1, 2, 3, 4, 5]
>>> for i in range(len(L)):
... L += 1 # this is a typo I made - should
have been L[i], not L.
[1, 7, 3, 4, 5]
I did correct my typo, but what I do not understand is how range arrived at
a '7', where the '2' should be. My best guess is that L is treated as
the index of the value '2'. I hope that learning how my error affected the
result will help me grasp the concept a little better.
Minister, Journalist, Free Software Advocate
sip:dcparris at ekiga.net <sip%3Adcparris at ekiga.net>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor