Modifying an element of a list in a function


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


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


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


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