Using two lists as two arguments in a function


#1



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


Oops, try again. join_lists([1, 2], [3, 4]) returned [1, 2, 3, 4, 5, 6] instead of [1, 2, 3, 4]


m = [1, 2, 3]
n = [4, 5, 6]

# Add your code here!
def join_lists(x, y):
    return m + n

print join_lists(m, n)
# You want this to print [1, 2, 3, 4, 5, 6]


#2

solved it
should be:
return x + y
instead of:
return m + n


#3

do you also understand why?


#4

because it is "join_lists(x, y)" not m, n


#5

look:

m = [1, 2, 3]
n = [4, 5, 6]

# function declarations with parameters x and y
def join_lists(x, y):
    return m + n

# function calls with arguments
print join_lists(m, n)
print join_list(['a', 'b', 'c'], ['d', 'e', 'f'])

see comments in code, when you call the function you supply arguments which get copied into the function parameters, this way, your function works for multiply lists


#6

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