Why does the function parameter matter so much?


#1



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


If I use the code below (calling the parameter "lst"), I get this error message: "list_extender([1, 2, 3, 4]) returned [3, 5, 7, 9, 9] instead of [1, 2, 3, 4, 9]".

If I change the name of the parameter that list_extender takes to "1st" ("first", I misread the instructions on my first try), I get this error message: "File "python", line 3 def list_extender(1st): ^ SyntaxError: invalid syntax"

If I go with "def list_extender(n)" it says "Congratulations, you've finished this section!" - even though I'm certain that using 'n' as the parameter isn't following the instructions for the exercise.


Why does it matter what I call this parameter? Am I correct in thinking that I don't actually have the exercise right when I use list_extender(n), even though Codecademy does pass that?


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


print list_extender(n)


#2

the first character of a variable name can't be an integer

well, what you name your parameter, but look at this code:

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


print list_extender(n)
print list_extender([1, 2, 3, 4])

the second function call doesn't print the correct output

so, it doesn't matter what you name the function parameter (as long as its a valid name) as long as you append to the function parameter, so your function works correctly for any list you pass as argument at function call

the argument at function call gets copied into the function parameter


#3

Oh! lst.append(9), then return lst? Cool: it works, and it makes sense, too! Thank you!


#4

Good to hear it all make sense, no more questions about parameters?


#5

Not yet: I'm still a total beginner at this :wink:


#6