Can someone please explain why return lst.append(9) did not work


#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?


My question isn't of high importants but is more curiousity than anything, For this excerise I expected this code to work:
return lst.append(9)

instead of

lst.append(9)
return lst

Can someone please explain why return lst.append(9) did not work; I thought it would be less code stating it all in one line.


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


print list_extender(n)


#2

from python docs:

list.append(x)
Add an item to the end of the list; equivalent to a[len(a):] = [x]

You can't assign and return at the same line, too many operations for a single line of code


#3

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