Modifying values in a list
Tim Williams (gmail)
tdwdotnet at gmail.com
Thu Dec 29 11:58:29 EST 2005
More information about the Python-list mailing list
Thu Dec 29 11:58:29 EST 2005
- Previous message (by thread): how to tell the version of tk shipped with Python
- Next message (by thread): Modifying values in a list
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 29 Dec 2005 08:43:17 -0800, tron.thomas at verizon.net < tron.thomas at verizon.net> wrote: > > The following code: > > numbers = [1, 2, 3] > for value in numbers: > value *= 2 > print numbers Above, you are modifying "value", not the item in the list >>> numbers = [1, 2, 3] >>> for x in range(len(numbers)): ... numbers[x] = numbers[x]*2 >>> numbers [2, 4, 6] HTH :) -- Tim Williams -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20051229/5871d436/attachment.html>
- Previous message (by thread): how to tell the version of tk shipped with Python
- Next message (by thread): Modifying values in a list
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list