List manipulation in functions


#1



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

The following code works:
n = [3, 5, 7]

Add your function here

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

print list_extender(n)

But the following does not return anything

n = [3, 5, 7]

Add your function here

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

print list_extender(n)


Can somebody please explain me why?


Replace this line with your code.


#2

Instructions
Define a function called list_extender that has one parameter lst.
Inside the function, append the number 9 to lst.
Then return the modified list.

The append method has no return value, hence the return from your function will be None.

lst.append(9)
return lst

has an explicit return value.


#3

I got it, thank you.


#4

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