1 00:00:00,236 --> 00:00:04,702 Okay, now that we've tackled sending a single value to a function with arguments 2 00:00:04,702 --> 00:00:09,270 and parameters, let's talk about sending multiple values to functions. 3 00:00:09,270 --> 00:00:11,521 The truth is, there really isn't much of a difference. 4 00:00:11,521 --> 00:00:14,386 You can send as many arguments to a function as you want, so 5 00:00:14,386 --> 00:00:17,120 long as it has a corresponding parameter. 6 00:00:17,120 --> 00:00:20,696 You simply separate the values with a comma when you call the function, and 7 00:00:20,696 --> 00:00:23,900 separate the parameters with a comma in the function definition. 8 00:00:23,900 --> 00:00:26,590 Let's revisit the add_two function and expand on it. 9 00:00:27,610 --> 00:00:30,550 To recap, the add_two function receives one argument. 10 00:00:30,550 --> 00:00:34,840 Stores the value of that argument in the parameter num. 11 00:00:34,840 --> 00:00:37,070 Then adds two to that parameter. 12 00:00:37,070 --> 00:00:39,060 Then it returns the sum. 13 00:00:39,060 --> 00:00:44,250 What if instead we wanted a function that would add any two integers together? 14 00:00:44,250 --> 00:00:47,730 To do this we could send two integers to the function when we call it and 15 00:00:47,730 --> 00:00:51,090 rewrite or function a little so that it can receive two arguments. 16 00:00:51,090 --> 00:00:55,222 Just follow along with me here and in a little while you'll have an opportunity to 17 00:00:55,222 --> 00:00:57,490 open up your workspace and try by yourself. 18 00:00:57,490 --> 00:01:03,133 First, we'll modify the function so we can receive a second parameter. 19 00:01:03,133 --> 00:01:07,658 I'll change this first parameter to num1 and then add a second one called num2. 20 00:01:07,658 --> 00:01:12,455 As you can see, all I did to make this happen was add a second parameter 21 00:01:12,455 --> 00:01:15,040 separated from the first by a comma. 22 00:01:16,075 --> 00:01:19,184 It's important to note that no two parameters can have the same name. 23 00:01:19,184 --> 00:01:22,446 If you give two parameters the same name the Python interpreter will send 24 00:01:22,446 --> 00:01:23,150 an error back. 25 00:01:24,420 --> 00:01:28,064 It's also very important to know that the arguments will be received in the order 26 00:01:28,064 --> 00:01:28,986 that they are sent. 27 00:01:28,986 --> 00:01:33,197 The first argument in the function call will always be received into the first 28 00:01:33,197 --> 00:01:36,110 parameter in the function definition. 29 00:01:36,110 --> 00:01:38,310 This is why these are called positional arguments, 30 00:01:38,310 --> 00:01:40,060 the order in which you send them matters. 31 00:01:40,060 --> 00:01:44,151 The position of the argument must correspond with the position 32 00:01:44,151 --> 00:01:45,391 of the parameter. 33 00:01:45,391 --> 00:01:49,826 Okay, now, in the body of the function let's edit the expression that's assigned 34 00:01:49,826 --> 00:01:53,400 to the val variable, so it adds these two new parameters together. 35 00:01:59,550 --> 00:02:02,712 Also, since the function was updated and does something different now, 36 00:02:02,712 --> 00:02:05,880 I'll also change the function name to something that's more accurate. 37 00:02:09,650 --> 00:02:13,595 And finally, let's fix our function call to reflect the new function name and 38 00:02:13,595 --> 00:02:15,040 the additional parameter. 39 00:02:18,457 --> 00:02:21,905 And so, for the second argument I'll just pick the integer 10 to send. 40 00:02:21,905 --> 00:02:25,156 Now, I'm gonna add a print statement around our function call so 41 00:02:25,156 --> 00:02:28,600 we can see the outcome of our changes when we save and run the program. 42 00:02:33,128 --> 00:02:36,800 All right, now, I'm gonna save and run down in our terminal. 43 00:02:47,377 --> 00:02:51,390 Awesome, it printed out 15 which is in fact the sum of 5 and 10. 44 00:02:51,390 --> 00:02:53,350 Now, it's your turn. 45 00:02:53,350 --> 00:02:55,610 Open up the attached workspace. 46 00:02:55,610 --> 00:02:59,643 Inside you'll see the unmodified add two function and a call to that function. 47 00:02:59,643 --> 00:03:03,423 After pausing the video here try to change up the add_two function so 48 00:03:03,423 --> 00:03:05,800 that it receives two arguments. 49 00:03:05,800 --> 00:03:09,260 The body of the function should multiply these two arguments together and 50 00:03:09,260 --> 00:03:10,890 then it should return that value. 51 00:03:10,890 --> 00:03:14,103 After that edit the function called to reflect the new number 52 00:03:14,103 --> 00:03:17,580 of required arguments and the new function name. 53 00:03:17,580 --> 00:03:20,744 When you're done check the teacher's note for the solution and 54 00:03:20,744 --> 00:03:21,980 then unpause the video. 55 00:03:21,980 --> 00:03:25,080 Welcome back, I hope that was a fun challenge for you. 56 00:03:25,080 --> 00:03:26,000 How did it go? 57 00:03:26,000 --> 00:03:27,585 Before moving on the the next stage, 58 00:03:27,585 --> 00:03:31,400 why don't you take a few moments to play around with your updated function. 59 00:03:31,400 --> 00:03:33,680 What happens if you don't pass two arguments? 60 00:03:33,680 --> 00:03:36,960 What happens if you pass a string instead of an integer? 61 00:03:36,960 --> 00:03:39,910 Try adding a third parameter and argument. 62 00:03:39,910 --> 00:03:42,734 Have fun with it and poke around before joining me in the next and 63 00:03:42,734 --> 00:03:44,027 final stage of this course. 64 00:03:44,027 --> 00:03:45,060 Keep on coding.