Why does this work (list manipulation)


#1

Please can some explain to me why this worked
n = [3, 5, 7]

Add your function here

def list_extender(lst):
lst.append(9)
return lst

print list_extender(n)

and not this
n = [3, 5, 7]

Add your function here

def list_extender(lst):

lst = lst.append(9)
return lst

print list_extender(n)

-=======================================
shouldn’t both perform the same operation but as i ran both, i got different values, the second code return “None” while the first code returned an updated list


#2

What does list.append return? What makes you say that its return value is useful and that you’d therefore want to hold on to that value with help of a variable? What does list.append do? What happens when you call it, where do you get the result?


#3

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