Why we need to build built in function


#1



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

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]


I would like to ask why we do need to have built in function join_lists in this exercise instead print n + m directly.


Replace this line with your code.


#2

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

Function makes your code generalized,by doing that You can use it for any two lists (not just m and n).
You can pass any two lists as argument of function and it will return sum of it.


#3

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