1 00:00:00,000 --> 00:00:03,564 Great, you can now create functions, call them, 2 00:00:03,576 --> 00:00:07,000 and add parameters to make them more dynamic. 3 00:00:07,001 --> 00:00:11,000 And now what you can also do is to make a function return a value. 4 00:00:11,001 --> 00:00:16,000 So this function, SayHello, is just a function that does an action. 5 00:00:16,001 --> 00:00:18,000 It doesn't return anything. 6 00:00:18,001 --> 00:00:19,000 Now I'm going to create a new function. 7 00:00:19,001 --> 00:00:24,000 So as you can see, when I just press Enter here, I still have the indentation. 8 00:00:24,001 --> 00:00:29,000 So what I'm going to do, I'm going to remove that indentation and do depth again. 9 00:00:29,001 --> 00:00:33,000 So let's say I'm going to create a function, double number. 10 00:00:33,001 --> 00:00:36,000 And let's say, hey, or just number. 11 00:00:36,001 --> 00:00:40,000 So you can create as many functions as you want. 12 00:00:40,001 --> 00:00:44,000 You just need to put them one after the other. 13 00:00:44,001 --> 00:00:50,000 Okay, so now I'm going to create a function with one parameter. 14 00:00:50,001 --> 00:00:52,000 And the name of the function is double number. 15 00:00:52,001 --> 00:00:56,000 And I simply want to return the double for this number. 16 00:00:56,001 --> 00:01:01,000 So I'm first going to compute the result, which is the double of that number. 17 00:01:01,001 --> 00:01:07,000 So I'm going to create a variable result is equal to number times two. 18 00:01:07,001 --> 00:01:12,000 And then what I'm going to do, I'm going to use the return statement. 19 00:01:12,001 --> 00:01:14,000 Return result. 20 00:01:14,001 --> 00:01:18,000 So what this function will do when it's called, 21 00:01:18,001 --> 00:01:21,000 so first it's going to receive a parameter number. 22 00:01:21,001 --> 00:01:25,000 It's going to compute the double of this number and return the result. 23 00:01:25,001 --> 00:01:29,000 So when you call the function, you can get the double of the number you send. 24 00:01:29,001 --> 00:01:33,000 Just before we continue, one thing I'm going to do here 25 00:01:33,001 --> 00:01:37,000 is that so we create a variable and we just return that variable. 26 00:01:37,001 --> 00:01:39,000 So basically, we are not going to use that. 27 00:01:39,001 --> 00:01:41,000 We only return that variable. 28 00:01:41,001 --> 00:01:46,000 So what I can do instead of result is equal to number times two and return result, 29 00:01:46,001 --> 00:01:51,000 I can just return number times two and remove that. 30 00:01:52,000 --> 00:01:56,000 So this is going to return directly the correct value. 31 00:01:56,001 --> 00:01:58,000 And now, well, I can call this function. 32 00:01:58,001 --> 00:02:02,000 So I'm first going to put a comment here. 33 00:02:02,001 --> 00:02:04,000 Okay, so we don't call those. 34 00:02:04,001 --> 00:02:05,000 So this is not a problem. 35 00:02:05,001 --> 00:02:06,000 You could call this and call this. 36 00:02:06,001 --> 00:02:08,000 That's not a problem. 37 00:02:08,001 --> 00:02:10,000 Here, I just want to call that function and not this one. 38 00:02:10,001 --> 00:02:14,000 So we just have less lines in the output. 39 00:02:14,001 --> 00:02:17,000 So what I can do, I can do double number. 40 00:02:17,001 --> 00:02:22,000 I can use the auto-completion with, let's say, three. 41 00:02:22,001 --> 00:02:25,000 Okay. And I'm going, of course, to store that. 42 00:02:25,001 --> 00:02:33,000 So let's say number is equal to double number three and then print number. 43 00:02:33,001 --> 00:02:38,000 So when you create a function that returns something with a return statement, 44 00:02:38,001 --> 00:02:41,489 when you call the function, you can actually 45 00:02:41,501 --> 00:02:45,000 assign the value you get here to a variable. 46 00:02:45,001 --> 00:02:47,000 And then you can print, of course, the variable, 47 00:02:47,001 --> 00:02:49,000 or you can do whatever you want with the variable. 48 00:02:49,001 --> 00:02:53,000 So I just run the program and you can see I have six. 49 00:02:53,001 --> 00:02:56,000 So the double of three is six. 50 00:02:56,001 --> 00:03:00,000 So the number variable here contains the value six. 51 00:03:00,001 --> 00:03:03,000 All right. So you can see two types of functions here. 52 00:03:03,001 --> 00:03:07,000 So those who are just going to do an action and don't return anything, 53 00:03:07,001 --> 00:03:13,000 and those who compute or maybe get a value from somewhere and then return that value. 54 00:03:13,001 --> 00:03:17,000 Note that you can return any kind of value you want. 55 00:03:17,001 --> 00:03:19,000 Here, I return an integer number. 56 00:03:19,001 --> 00:03:25,000 But you can return a float, a Boolean, a string, list of whatever you want, 57 00:03:25,001 --> 00:03:28,000 while just return what you want from the function. 58 00:03:28,001 --> 00:03:31,000 But just make sure that when you call the function, 59 00:03:31,001 --> 00:03:34,000 you actually know what kind of data type you are going to get. 60 00:03:34,001 --> 00:03:36,919 Okay. And one thing you can also do is you 61 00:03:36,931 --> 00:03:40,000 can call a function inside another function. 62 00:03:40,001 --> 00:03:44,000 And thus, you can really make functions as building blocks 63 00:03:44,001 --> 00:03:47,000 that allow you to create even more building blocks. 64 00:03:47,001 --> 00:03:48,241 Let's see that with an example. 65 00:03:49,000 --> 00:03:54,000 Def print double number. 66 00:03:54,001 --> 00:03:58,776 So with number, and I'm going to do result is 67 00:03:58,788 --> 00:04:08,000 equal to double number of the number we get here, and then print result. 68 00:04:08,001 --> 00:04:11,000 Or maybe make it better. 69 00:04:11,001 --> 00:04:18,989 So double of plus the number casted as a string, plus 70 00:04:19,001 --> 00:04:27,000 is, and then plus the result also casted as a string. 71 00:04:27,001 --> 00:04:30,380 So when you call this function, what it's going 72 00:04:30,392 --> 00:04:34,000 to do is going to call the double number function. 73 00:04:34,001 --> 00:04:37,000 Okay. So from the function, you call another function. 74 00:04:37,001 --> 00:04:39,000 And you can see this parameter I got here, 75 00:04:39,001 --> 00:04:42,000 I'm going to pass it also to the double number function. 76 00:04:42,001 --> 00:04:47,000 And then I can print some stuff with the parameter and the result I got. 77 00:04:47,001 --> 00:04:53,000 And I'm going to call it this print double number. 78 00:04:53,001 --> 00:04:54,000 I'm going to remove that. 79 00:04:54,001 --> 00:04:57,000 And I'm going to remove that. 80 00:04:57,001 --> 00:04:59,000 And I'm simply going to run. 81 00:04:59,001 --> 00:05:03,000 And you can see double of three is six. 82 00:05:03,001 --> 00:05:06,000 Okay. It's all happening in that function. 83 00:05:06,001 --> 00:05:10,000 So here you have a function that just does an action and that's it. 84 00:05:10,001 --> 00:05:13,000 Here, a function that returns a number. 85 00:05:13,001 --> 00:05:15,545 And here, a function that does an action, but 86 00:05:15,557 --> 00:05:18,000 inside, you actually call another function. 87 00:05:18,001 --> 00:05:20,432 And you can create another function that is 88 00:05:20,444 --> 00:05:23,000 going to call that one, et cetera, et cetera.