1 00:00:00,520 --> 00:00:05,560 Kelly guys and welcome back to another class of our course about the complete introduction to Python. 2 00:00:05,580 --> 00:00:07,290 We saw a lot of things in this course. 3 00:00:07,440 --> 00:00:10,200 And since right now we are talking about functions. 4 00:00:10,200 --> 00:00:15,590 I think that I think is very important about functions will be the return statement. 5 00:00:15,600 --> 00:00:19,760 And for me this is something that is very important. 6 00:00:19,840 --> 00:00:25,720 So what is exactly the return statement and how exactly can it work in functions. 7 00:00:25,720 --> 00:00:32,680 Well it's very simple the return statement is simply a statement that is used to end the execution of 8 00:00:32,980 --> 00:00:33,970 a certain function. 9 00:00:34,720 --> 00:00:35,800 So what does this mean. 10 00:00:36,160 --> 00:00:43,580 This means when you run the return statement everything that is after it will not be taken into consideration 11 00:00:43,640 --> 00:00:47,370 and will not be printed in our function. 12 00:00:47,420 --> 00:00:52,200 So let's say for example you want to end up a certain function at a certain place. 13 00:00:52,280 --> 00:00:58,100 You simply enter your return statement and your function will end up at this particular place. 14 00:00:58,100 --> 00:00:59,570 This works for a string. 15 00:00:59,570 --> 00:01:00,740 This works for numbers. 16 00:01:00,740 --> 00:01:04,560 This works for boolean it works for absolutely everything. 17 00:01:04,580 --> 00:01:05,690 Let me show you a quick example. 18 00:01:05,690 --> 00:01:07,550 So let's say we write down a simple function. 19 00:01:07,560 --> 00:01:10,640 So in this case it will be a calculation function. 20 00:01:10,720 --> 00:01:12,800 Let's say we have our calculation 21 00:01:15,470 --> 00:01:17,330 and we'll have our elements. 22 00:01:17,330 --> 00:01:21,960 That will be A B C grade. 23 00:01:21,980 --> 00:01:27,290 So next thing that we want to do we'll write down our calculations so let's say we want to Python to 24 00:01:27,290 --> 00:01:29,650 print some outcomes. 25 00:01:29,870 --> 00:01:37,360 In this case we'll have a plus b plus c we want to print up 26 00:01:43,870 --> 00:01:45,250 A minus B minus C 27 00:01:52,240 --> 00:01:56,490 a multiplied by B and divided by c. 28 00:01:56,700 --> 00:01:57,020 Good. 29 00:01:59,050 --> 00:02:02,120 So right now our up is consisted of three lines of code. 30 00:02:02,690 --> 00:02:09,280 And if we run our up in this case let's run it. 31 00:02:09,340 --> 00:02:16,660 So calculation let's name our variables one two and three and let's run our up. 32 00:02:16,750 --> 00:02:22,930 So when we run our up as you can see the answer will be six minus four and zero point 6 6 6 6 6. 33 00:02:22,940 --> 00:02:23,230 All right. 34 00:02:23,260 --> 00:02:26,680 So let's say for example we don't need those two lines of code right. 35 00:02:26,680 --> 00:02:27,300 Well we don't. 36 00:02:27,310 --> 00:02:31,090 The last line of code we just need the two first lines. 37 00:02:31,170 --> 00:02:32,040 So what we'll do. 38 00:02:32,070 --> 00:02:33,020 It's very simple. 39 00:02:33,030 --> 00:02:38,480 We'll go at the same line and simply write down our written statement right here. 40 00:02:38,610 --> 00:02:42,590 You can see we have our third line of code but everything will stop right there. 41 00:02:42,900 --> 00:02:47,280 So we can run our up as you can see this will be our answer. 42 00:02:47,280 --> 00:02:58,550 If we add for example a string let's say you print this is a calculation. 43 00:02:58,620 --> 00:03:03,580 So if we add a string as you can see right there and run up it's going to still work. 44 00:03:03,750 --> 00:03:09,260 But if we add a string after the return calculation the return statements are. 45 00:03:10,060 --> 00:03:19,450 So in this case let's say we write down something and we run our up as you can see it still returns 46 00:03:19,450 --> 00:03:23,390 us only the first part of the statement. 47 00:03:23,740 --> 00:03:31,280 So in this case as so the return segment as I explained is very very useful in the case of if you want 48 00:03:31,280 --> 00:03:34,040 to for example stop a function at a certain place. 49 00:03:34,040 --> 00:03:39,590 So if for example you need only a certain part of a certain function at a certain place well you can 50 00:03:39,590 --> 00:03:42,580 stop your function at a certain place. 51 00:03:42,590 --> 00:03:48,930 For example it's a long calculation that is the draw function is a long calculation of as many steps. 52 00:03:48,950 --> 00:03:52,220 So say for example you want to stop your calculation at the second step. 53 00:03:52,220 --> 00:03:56,400 Well we can just put your return statement at the end of the second step and that's it. 54 00:03:56,420 --> 00:03:58,910 It will not run what's coming after. 55 00:03:58,940 --> 00:04:05,750 So in this case here we have our two steps so the first step will be to print a plus b plus c the same 56 00:04:05,750 --> 00:04:06,830 step will be printing. 57 00:04:06,830 --> 00:04:10,680 This is a calculation third step will be printing A minus B minus C. 58 00:04:10,850 --> 00:04:13,680 And this is where we will stop our calculations. 59 00:04:13,850 --> 00:04:17,000 Everything after this statement will disappear. 60 00:04:17,000 --> 00:04:18,800 So wheel well will not disappear. 61 00:04:18,800 --> 00:04:24,760 It will not be used in our function as you can see it's something that is very very useful and the key 62 00:04:24,760 --> 00:04:30,260 is that if you want to for example cut your functions at certain places there are other things that 63 00:04:30,260 --> 00:04:30,850 you can't. 64 00:04:30,860 --> 00:04:32,420 Well there are other utilities. 65 00:04:32,420 --> 00:04:33,720 The return statement. 66 00:04:33,860 --> 00:04:37,670 But once again this is the main one and this is the most important one. 67 00:04:38,120 --> 00:04:41,270 So let's say for the stats guys in C all in our next class.