List manipulations in functions


#1



https://www.codecademy.com/courses/python-beginner-nzzVa/2/4?curriculum_id=4f89dab3d788890003000096


Oops, try again. list_extender([1, 2, 3, 4]) returned None, did you remember to return the result?


n = [3, 5, 7]
# Add your function here
def list_extender(lst):
    lst = lst.append(9)
    return lst





print list_extender(n)


#2

this one helped..
BUT , now i would like to know what is the logic that the first one didn't work while this one did
n = [3, 5, 7]

Add your function here

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

print list_extender(n)


#3

function return None by default.

Given .append() modifies the list directly, there is no need for append to return anything, but function always have to return, so None is returned

in your first approach, you would store the returned result (None) into list, overwriting your list with None


#4

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