Modifying an element


Hi there

Why is this multiplying and not (as shown in the example!) copying the number? And why is everybody suddenly using for in range (when looking at other questions in Q&A)?:sweat:

I get [6, 5, 7]..

the example for the exercise was:def double_first(n):
n[0] = n[0] * 2

numbers = [1, 2, 3, 4]
print numbers

def list_function(x):
    x[0] = x[0] * 2
    return x

n = [3, 5, 7]
print n


are you at Modifying an element of a list in a function? this exercise?

Exactly which exercise are you at? Please copy paste the url of the exercise to the forum


seems like you are, this exercise asks you to:
Add 3 to the item at index one of the list
you seem to multiply the item at index 0. Which is not what the exercise asked of you. No one is using range for this question, that is later


exactly. ok what is the example for then? I tought I could apply this to my code.


Ok, never mind. I understood it know.. thanks!!


No, the example roughly shows how something is done. If it exactly what needs to be done the exercise, you would just be copying it. So the example is to help you in the right direction, and then you have to think how to apply the explanation into your coding problem