As others have already posted, changing the value of 'value' has
nothing to do with the list variable 'numbers'. To modify the list in
place, you need to access its members by index. The following code
does this:
numbers = [1,2,3]
for i in range(len(numbers)):
numbers[i] *= 2
print numbers
On 29 Dec 2005 08:43:17 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]
> wrote:The following code:numbers = [1, 2, 3]for value in numbers:
value *= 2print numbers
Above, you are modifying "value", not the item in the list
>>> numbers = [1, 2, 3]
>>> for x in range(len(numbers)):
... num
On Thu, 2005-12-29 at 11:43, [EMAIL PROTECTED] wrote:
> The following code:
>
> numbers = [1, 2, 3]
> for value in numbers:
> value *= 2
> print numbers
>
> results in the following output:
> [1, 2, 3]
>
> The intent of the code was to produce this output:
> [2, 4, 6]
>
> What is the reas
[EMAIL PROTECTED] said unto the world upon 29/12/05 10:43 AM:
> The following code:
>
> numbers = [1, 2, 3]
> for value in numbers:
> value *= 2
> print numbers
>
> results in the following output:
> [1, 2, 3]
>
> The intent of the code was to produce this output:
> [2, 4, 6]
>
> What is
[EMAIL PROTECTED] writes:
> The following code:
>
> numbers = [1, 2, 3]
> for value in numbers:
> value *= 2
> print numbers
>
> results in the following output:
> [1, 2, 3]
>
> The intent of the code was to produce this output:
> [2, 4, 6]
>
> What is the reason for the output produced?
> W
The following code:
numbers = [1, 2, 3]
for value in numbers:
value *= 2
print numbers
results in the following output:
[1, 2, 3]
The intent of the code was to produce this output:
[2, 4, 6]
What is the reason for the output produced?
What code should be used to obtain the desired outpu