1 00:00:00,120 --> 00:00:03,370 Syntax for defining a function. 2 00:00:03,600 --> 00:00:09,810 If you observe the last statement in the function body is it a done statement. 3 00:00:09,810 --> 00:00:18,990 And when a written statement is encountered inside a function the function dominate and the value of 4 00:00:18,990 --> 00:00:27,660 the expression followed by the return keyword is sent back to the part of the program that called the 5 00:00:27,900 --> 00:00:34,860 function and this expression within the square brackets is optional. 6 00:00:34,860 --> 00:00:41,400 If you provide this expression by then evaluates this expression and returns the result. 7 00:00:41,400 --> 00:00:42,810 Consider this example. 8 00:00:42,810 --> 00:00:50,660 I have defined a function and which takes two arguments A and B and it has a print function and then 9 00:00:50,830 --> 00:00:53,000 it don't statement in the function body. 10 00:00:54,260 --> 00:01:03,830 And also I have defined another function some which takes two arguments and print the sum of these two 11 00:01:03,920 --> 00:01:05,410 variables. 12 00:01:05,660 --> 00:01:08,880 So let execute both of these functions. 13 00:01:08,900 --> 00:01:10,100 Indeed you put a notebook. 14 00:01:10,610 --> 00:01:16,060 So here I have defined this function which contains a written statement. 15 00:01:16,580 --> 00:01:18,500 So let execute this 16 00:01:21,220 --> 00:01:30,720 and as you can see the written statement has evaluated this expression and return the result. 17 00:01:31,360 --> 00:01:38,360 Now coming to the next function some let's execute this code as well. 18 00:01:38,770 --> 00:01:46,750 And the sum function has return the sum of these two arguments. 19 00:01:46,830 --> 00:01:54,340 So what is the difference between the function add and the function sum. 20 00:01:54,560 --> 00:02:04,670 These functions which returns values are known as value returning functions as functions which do not 21 00:02:04,670 --> 00:02:09,440 return any values are called Wide functions. 22 00:02:09,440 --> 00:02:19,010 So also a function that returns a value produces a value for use by the program or in particular for 23 00:02:19,010 --> 00:02:23,120 use in part of the code ready function was invoked. 24 00:02:23,570 --> 00:02:25,150 So what do we mean by that. 25 00:02:25,160 --> 00:02:31,070 So in order to better understand this let's do one in order to make the. 26 00:02:31,100 --> 00:02:37,060 It is the return value available to the program as it continues executing. 27 00:02:37,790 --> 00:02:49,900 We can assign this function call to a variable so here I have assigned a variable to this function call. 28 00:02:50,020 --> 00:02:57,760 And after you make the function call to this program the function gets executed and the value that does 29 00:02:57,760 --> 00:03:04,260 it at dawn is assigned to this variable white and as a next step. 30 00:03:04,490 --> 00:03:12,450 Letters modify or change perform some mathematical operations on this variable right. 31 00:03:12,460 --> 00:03:22,180 So let's say let's multiply the variable y with minus 1 and then put in this variable Y. 32 00:03:23,110 --> 00:03:25,790 So let's execute this code. 33 00:03:25,930 --> 00:03:35,260 So as you can see that adorned value from the function has been saved to this variable Y and b have 34 00:03:35,260 --> 00:03:38,980 performed some operations on this variable. 35 00:03:39,490 --> 00:03:42,510 And then finally printed this variable. 36 00:03:42,550 --> 00:03:45,790 Now let us do the same thing. 37 00:03:45,880 --> 00:03:56,140 That means let us also assign a sign of variable Zi to the function call sum of 4 and 5. 38 00:03:56,140 --> 00:03:58,360 So let's execute this. 39 00:03:58,360 --> 00:04:04,840 So in order to understand the difference between a value the turning function and a wide function I 40 00:04:04,840 --> 00:04:07,770 have assigned a variable to this function call. 41 00:04:07,870 --> 00:04:14,220 So zi is equal to some of the variables 4 and 5. 42 00:04:14,380 --> 00:04:23,800 And once we execute the code in this cell the number 9 that you see in the output is being printed using 43 00:04:23,800 --> 00:04:35,660 this print function and then none is being printed using this print function so Zi has been assigned 44 00:04:35,750 --> 00:04:47,620 a value none and all functions in that redefine in python have order done value even if there is no 45 00:04:47,710 --> 00:04:58,110 return statement inside the code and functions without a written statement it on a special value note 46 00:04:58,250 --> 00:05:10,840 NES none which is equal in two files and the interpreter does not print none so that is the reason when 47 00:05:11,140 --> 00:05:21,780 we have executed this function so when you execute this function which has no order done state Min 48 00:05:24,400 --> 00:05:33,780 the brain function displays defining the sum of these two variables but devalue none as not Red Dawn. 49 00:05:33,790 --> 00:05:39,990 That's because the interpreter does not print none in this function. 50 00:05:39,990 --> 00:05:45,280 I have omitted the expression in the return keyboard. 51 00:05:45,360 --> 00:05:55,320 In that case when you execute this function in this code dysfunction you don't none nada to check that 52 00:05:55,320 --> 00:05:56,820 you can assign this 53 00:05:59,610 --> 00:06:06,670 the function call to a variable M that display m. 54 00:06:07,130 --> 00:06:15,090 And if you check the type of this variable m it is of D data type none type. 55 00:06:18,180 --> 00:06:28,470 The variability has been assigned none because the print function does not assign a value to a variable 56 00:06:28,920 --> 00:06:38,750 and it does not return a value from a function called and that is the reason the variable G has been 57 00:06:38,750 --> 00:06:41,510 assigned the value none. 58 00:06:41,510 --> 00:06:49,880 We can also have multiple written statements inside the function but as soon as the first return statement 59 00:06:49,880 --> 00:06:56,600 has encountered the function terminate and all these statements following the written statement are 60 00:06:56,600 --> 00:06:57,860 not executed. 61 00:06:59,560 --> 00:07:01,570 So let's see this example. 62 00:07:01,600 --> 00:07:12,460 So we have the if elif added statement here and each of these statements contain the return statement. 63 00:07:12,460 --> 00:07:22,970 So when we execute this function after one of the conditions becomes true the written statement is executed. 64 00:07:23,090 --> 00:07:28,790 And all these statements following the written statement are not executed. 65 00:07:29,600 --> 00:07:38,570 So when one of these conditions is true the return statement within that condition get executed and 66 00:07:38,570 --> 00:07:46,160 the function terminates and all these statements following it are not executed and a written statement 67 00:07:46,160 --> 00:07:49,850 can also return multiple values from a function. 68 00:07:50,600 --> 00:07:57,440 So in order to do that you can separate each of these expressions here with a comma. 69 00:07:57,440 --> 00:08:00,830 So let execute this code. 70 00:08:00,830 --> 00:08:09,170 So a tuple is written in case you want to have the result saved in different variables. 71 00:08:09,320 --> 00:08:18,890 You what you can do is you can defined three different variables C L comma and comma n and assign these 72 00:08:18,890 --> 00:08:25,480 variables to the function call now and then let print each of these variables. 73 00:08:27,630 --> 00:08:38,360 In and then M and in so as you can see the the return value from each of these expressions inside the 74 00:08:38,540 --> 00:08:49,770 return statement have been saved in the variables L M N and and this is about the return statement.