1 00:00:00,430 --> 00:00:03,029 Welcome back. Now, let's talk about 2 00:00:03,349 --> 00:00:06,460 parameters and arguments. 3 00:00:06,849 --> 00:00:11,039 See a parameter is basically an input 4 00:00:11,310 --> 00:00:16,750 that we can add to a function in order to customize its behavior 5 00:00:18,049 --> 00:00:20,500 in this case right now, in the previous example, 6 00:00:20,829 --> 00:00:24,950 the name of the function, which is great, it didn't have any parameters at all. 7 00:00:24,959 --> 00:00:26,430 It's basically empty. 8 00:00:26,850 --> 00:00:27,950 That's why 9 00:00:28,319 --> 00:00:32,159 when we said OK, print and then simply hello world and then we call the function. 10 00:00:32,168 --> 00:00:35,900 All it simply did was just simply say hello world. 11 00:00:36,060 --> 00:00:40,950 But what if we now want to add a particular parameter inside in this case right now, 12 00:00:40,959 --> 00:00:43,549 I'm going to come in here right now and say name. 13 00:00:44,009 --> 00:00:44,630 OK. 14 00:00:44,990 --> 00:00:48,689 So the parameter right here is called name. And now 15 00:00:48,990 --> 00:00:51,619 I want my function to say 16 00:00:51,810 --> 00:00:56,009 hello and then the name that will be provided. 17 00:00:56,409 --> 00:00:57,009 So 18 00:00:57,209 --> 00:01:00,729 I'm going to come over here right now. Let's use the F string. 19 00:01:01,270 --> 00:01:05,489 And now I'm going to add my curly braces, color brackets rather 20 00:01:06,470 --> 00:01:09,150 and call it name. 21 00:01:09,819 --> 00:01:10,610 OK. 22 00:01:11,050 --> 00:01:13,970 So now check this out 23 00:01:15,449 --> 00:01:21,830 when I'm calling my function right now, I can add what we call the argument. 24 00:01:22,480 --> 00:01:26,819 When you're passing a value to the function, 25 00:01:27,300 --> 00:01:29,879 it's going to become an argument. 26 00:01:30,080 --> 00:01:33,830 Please note the difference between parameters and arguments 27 00:01:34,379 --> 00:01:37,470 up here. When we're first defining the function, 28 00:01:37,980 --> 00:01:42,190 we're gonna use the parameter. The parameter is 29 00:01:42,389 --> 00:01:44,089 basically all saying, hey, 30 00:01:44,349 --> 00:01:47,660 we're providing you with this input and I'm going to use 31 00:01:47,669 --> 00:01:52,029 this input to customize how you the function grid will behave. 32 00:01:52,050 --> 00:01:53,040 However, 33 00:01:53,504 --> 00:01:55,644 once the function has been created, 34 00:01:55,654 --> 00:01:58,184 we've told what the function is supposed to do in this case right now. 35 00:01:58,194 --> 00:02:00,555 Hello and then name the parameter. 36 00:02:00,995 --> 00:02:02,904 When we call that function. 37 00:02:02,985 --> 00:02:07,815 When we want to provide a value, it's going to become what we call an argument. 38 00:02:07,824 --> 00:02:09,005 So in this case, right now, 39 00:02:09,115 --> 00:02:12,794 if I wanted to greet, let's say Alice, for example, right, 40 00:02:13,014 --> 00:02:16,835 Alice right now is the argument. And if I was to run the program, 41 00:02:16,964 --> 00:02:23,354 there you go. It says hello, Alice. What if I wanted to greet? Let's say Bob, 42 00:02:24,199 --> 00:02:24,690 right, 43 00:02:25,580 --> 00:02:26,240 Bob, 44 00:02:26,559 --> 00:02:30,679 let's go ahead and run the program and there it is. Hello, Bob. 45 00:02:31,389 --> 00:02:32,740 These are 46 00:02:32,880 --> 00:02:36,100 parameters and arguments. 47 00:02:36,410 --> 00:02:37,529 However, 48 00:02:38,070 --> 00:02:42,110 we can also have multiple parameters 49 00:02:42,610 --> 00:02:44,009 in our function. 50 00:02:44,020 --> 00:02:47,199 So far right now, we've only been working with one single parameter which is name. 51 00:02:47,679 --> 00:02:48,929 What if 52 00:02:49,059 --> 00:02:53,169 we wanted to create a function that will add two numbers together? 53 00:02:53,919 --> 00:02:55,300 How are we going to do that? Well, 54 00:02:55,979 --> 00:02:59,539 we can start off by defining the function name. So I'm going to call this one. Add 55 00:03:00,000 --> 00:03:01,440 numbers, 56 00:03:02,979 --> 00:03:04,960 add numbers will be the name of the function. 57 00:03:05,320 --> 00:03:07,059 And now inside 58 00:03:07,529 --> 00:03:12,119 we're going to provide two parameters which are going to be A and B 59 00:03:12,380 --> 00:03:13,179 colon. 60 00:03:13,429 --> 00:03:14,059 OK? 61 00:03:14,470 --> 00:03:15,440 Now 62 00:03:16,479 --> 00:03:17,830 return 63 00:03:17,949 --> 00:03:20,309 A plus B, 64 00:03:20,589 --> 00:03:22,830 we haven't talked about the return function 65 00:03:22,979 --> 00:03:24,440 or return statement yet. 66 00:03:24,610 --> 00:03:27,300 What return does here is that it's simply 67 00:03:28,080 --> 00:03:30,660 going to return the value 68 00:03:31,550 --> 00:03:34,610 of a particular operation. In this case right now 69 00:03:34,910 --> 00:03:36,130 is going to return 70 00:03:36,820 --> 00:03:44,679 the values of A and B when they are added together. That's what the return does. So now 71 00:03:44,869 --> 00:03:45,960 I'm gonna come in here 72 00:03:46,619 --> 00:03:48,759 and say uh results, 73 00:03:49,229 --> 00:03:50,369 OK? Results 74 00:03:50,610 --> 00:03:52,710 is going to be equal to 75 00:03:52,970 --> 00:03:53,720 add 76 00:03:54,750 --> 00:03:55,820 numbers. 77 00:03:56,729 --> 00:03:59,229 OK? And now inside 78 00:03:59,729 --> 00:04:04,589 I can add the two numbers. I want to add, let's say five and six. 79 00:04:05,729 --> 00:04:07,789 And now all I will have to do 80 00:04:08,070 --> 00:04:09,990 is to simply print 81 00:04:11,009 --> 00:04:11,729 the result. 82 00:04:15,059 --> 00:04:15,759 And there it is. 83 00:04:17,200 --> 00:04:18,510 If I run my function, 84 00:04:18,839 --> 00:04:20,140 there you go. 11, 85 00:04:21,118 --> 00:04:25,348 you see how this works. First of all, we created a function 86 00:04:25,498 --> 00:04:28,269 but isn't the defined function called add numbers. OK? 87 00:04:28,278 --> 00:04:29,408 That's the name of a function. 88 00:04:29,709 --> 00:04:35,289 And then we said, OK, our function is going to receive two parameters A and B. 89 00:04:35,778 --> 00:04:40,479 And now with the return, we're basically defining what the function is going to do. 90 00:04:40,489 --> 00:04:44,058 It's going to return the value of A plus B. 91 00:04:44,369 --> 00:04:45,269 Now, 92 00:04:45,540 --> 00:04:48,350 all we need to do is to create a variable 93 00:04:48,630 --> 00:04:52,220 that will store the value of our function. 94 00:04:52,230 --> 00:04:57,130 So now the variable here is called the result, which is equal to add number. 95 00:04:57,140 --> 00:04:59,790 The name of the function call in right now 96 00:05:00,049 --> 00:05:02,489 with the two values which are five and six. 97 00:05:02,690 --> 00:05:06,899 And now we simply printed out results which is equal to 11. 98 00:05:07,250 --> 00:05:10,589 That's exactly how parameters arguments and 99 00:05:10,809 --> 00:05:13,200 the return function also works. 100 00:05:13,399 --> 00:05:15,390 By the way before 101 00:05:16,380 --> 00:05:17,790 I run up the video, 102 00:05:18,000 --> 00:05:21,260 just a very quick word on the return statement. 103 00:05:21,619 --> 00:05:24,920 It's used for two main purposes. OK? 104 00:05:25,160 --> 00:05:28,959 The first purpose is typically to exit a function 105 00:05:29,339 --> 00:05:32,079 so you can use it to stop function execution. 106 00:05:32,260 --> 00:05:34,660 Second is to return an actual value. So 107 00:05:34,950 --> 00:05:36,279 as an example, 108 00:05:36,559 --> 00:05:40,480 let me just show you real quick if I set the fine and then greet, 109 00:05:41,459 --> 00:05:42,119 OK, 110 00:05:42,260 --> 00:05:43,200 let me add 111 00:05:43,440 --> 00:05:45,359 empty parameters in here. 112 00:05:45,790 --> 00:05:48,640 And I said print, hello 113 00:05:49,170 --> 00:05:51,160 and then I said return, 114 00:05:52,829 --> 00:05:56,890 all right. But then after return on another line, I also say print 115 00:05:57,410 --> 00:05:59,630 and then let's say, uh 116 00:06:00,920 --> 00:06:02,130 let me say 117 00:06:02,339 --> 00:06:03,890 my coats. 118 00:06:04,450 --> 00:06:05,920 Hello, 119 00:06:06,510 --> 00:06:07,250 Jack. 120 00:06:08,369 --> 00:06:11,799 You can even see right now that within our replete, 121 00:06:12,149 --> 00:06:12,829 it's 122 00:06:13,140 --> 00:06:16,450 the text itself is kind of faded out, 123 00:06:16,559 --> 00:06:20,029 meaning that Python will not execute this particular 124 00:06:20,149 --> 00:06:22,380 line. So if I was to run, 125 00:06:23,220 --> 00:06:26,579 you can see right now it does absolutely nothing at all. 126 00:06:26,589 --> 00:06:28,799 But that's because I haven't called the function yet. So 127 00:06:29,079 --> 00:06:31,200 let me come over here and say greets and then 128 00:06:31,529 --> 00:06:33,170 brackets and there you go. So 129 00:06:33,290 --> 00:06:37,399 if I was to run the function right now, you can see all it says is going to be hello. 130 00:06:37,570 --> 00:06:41,649 Why? Because return right here signifies that, hey, 131 00:06:42,119 --> 00:06:46,519 stop the execution of the function. It shouldn't go beyond this particular line 132 00:06:46,809 --> 00:06:49,269 and that's why we only have hello. However, 133 00:06:49,459 --> 00:06:51,239 if I was to remove 134 00:06:51,619 --> 00:06:53,000 the return statement 135 00:06:53,619 --> 00:06:58,399 and I run the program again, you can see right now it says hello and then hello Jack. 136 00:06:58,739 --> 00:07:01,980 So this is another use of the return statement. 137 00:07:01,989 --> 00:07:05,920 You can use it to stop function execution or like I showed you earlier, 138 00:07:06,420 --> 00:07:12,109 you can use the return statement to return a particular value. 139 00:07:12,510 --> 00:07:15,420 Thank you for watching the video. I will see you in the next class.