Modifying an element of a list in a function


#1

I am not able to do this?

Change list_function so that:

Add 3 to the item at index one of the list.
Store the result back into index one.
Return the list.

def list_function(x):
x[1] = 3

n = [3, 5, 7]
print list_function(n)
print n


#2

You are missing just one little important thing,

should be,

x[1] += 3

And after that line you will need a return statement,

return x


#3

Thank you brother. Hope to get such help from you in future also.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.