Using two lists as two arguments in a function


#1

https://www.codecademy.com/courses/learn-python/lessons/lists-and-functions/exercises/using-two-lists-as-two-arguments-in-a-function?action=lesson_resume&link_content_target=interstitial_lesson

Hi I’m trying to understand how the following code works. I’m lost.

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

Add your code here!

def join_lists(x, y):
return x + y

print join_lists(m, n)

You want this to print [1, 2, 3, 4, 5, 6]

How is that the function arguments know which list they should use? How does x know it is taking the data from list ''n" and the same for y in list “m”. I simply don’t understand how it knows what to use?

Can someone help explain this?

Thanks,

J


#2

what you use here is known as positional arguments, the name gives a big clue about how it works. the first argument (m) will pass it value to the first parameter (x), same for second argument and parameter


#3

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