1 00:00:00,430 --> 00:00:07,720 Biton, global, local and non-local variables, so that means the variable, depending upon the scope, 2 00:00:08,110 --> 00:00:13,090 we shall call it as a global variable, local variable and nonlocal variable. 3 00:00:14,140 --> 00:00:16,160 So let us discuss them one by one. 4 00:00:16,180 --> 00:00:19,630 So at first we are going for the global variables available. 5 00:00:19,660 --> 00:00:25,570 We just declared outside of the function or in global scope is known as the global variable. 6 00:00:26,320 --> 00:00:31,460 This means that the global biddable can be accessed inside or outside of the function. 7 00:00:31,480 --> 00:00:37,660 So that very variable can be accessed within the function of outside of the function because it is under 8 00:00:37,660 --> 00:00:45,280 the global scope, local variables available which is defined or declared inside the functions body 9 00:00:45,640 --> 00:00:52,240 that is within the function body where defined one variable or in the local scope is called the local 10 00:00:52,240 --> 00:00:54,340 variable that is within the function body. 11 00:00:54,340 --> 00:00:57,100 The optimal has got defined or in the local scope. 12 00:00:57,250 --> 00:01:00,550 Then the variable will be known as the local variable. 13 00:01:00,790 --> 00:01:06,430 So in case a global variable, the variable will be will be defined or will be declared outside of the 14 00:01:06,430 --> 00:01:12,490 function in the global scope in case of local variables, the variable will be defined or will be declared 15 00:01:12,490 --> 00:01:14,620 within the function or in the local scope. 16 00:01:15,250 --> 00:01:21,520 What about, in that case, nonlocal variables, not local variables that are used in nested function 17 00:01:21,700 --> 00:01:24,660 whose local scope is not defined? 18 00:01:24,970 --> 00:01:31,000 So that means within the nested functions we are defining or we are using one variable which is not 19 00:01:31,000 --> 00:01:33,280 locally defined within the function itself. 20 00:01:33,610 --> 00:01:39,690 This means that the variable can be can be neither in the local nor in the global scope. 21 00:01:39,700 --> 00:01:43,220 So those variables will be known as non-local variables. 22 00:01:43,390 --> 00:01:46,450 I think the conceptual conception is not getting clear to us. 23 00:01:46,630 --> 00:01:49,990 So let us go for one practical demonstration for the better understanding. 24 00:01:50,650 --> 00:01:56,260 In this example, we have defined one X which has been defined outside of the function function one. 25 00:01:56,530 --> 00:02:01,220 So it is a global variable X and we just we just containing the string global here. 26 00:02:01,810 --> 00:02:07,300 So here within the function function one, we have defined this global X that is referring to the same 27 00:02:07,300 --> 00:02:08,740 X variable here. 28 00:02:09,190 --> 00:02:16,040 Y is having the scope local and it has got initialized with the local string, X is equal to two. 29 00:02:16,060 --> 00:02:18,610 So X is having the string global two. 30 00:02:18,910 --> 00:02:24,220 This global will be repeated twice, the string will become global, global and that will be assigned 31 00:02:24,220 --> 00:02:25,540 to the X back again. 32 00:02:25,960 --> 00:02:28,730 We are going to print the value of X and Y respectively. 33 00:02:29,260 --> 00:02:31,200 So now we are calling this function one. 34 00:02:31,210 --> 00:02:36,520 But before calling this function one and after calling this function one, we have also printing the 35 00:02:36,520 --> 00:02:37,580 value of X here. 36 00:02:37,960 --> 00:02:39,130 So here is the outcome. 37 00:02:39,130 --> 00:02:45,130 You can easily find that initially that that means before calling this function one, the global X is 38 00:02:45,130 --> 00:02:47,740 having the value globally within the function. 39 00:02:47,920 --> 00:02:50,800 When it is printing X, it is printing global, global. 40 00:02:51,160 --> 00:02:53,850 When it is printing, why it is printing local. 41 00:02:54,160 --> 00:02:59,710 And whenever we are printing this global expec again after the execution of this function, one, we 42 00:02:59,710 --> 00:03:06,040 are getting this one as global global because this particular biddable ex is having the it has been 43 00:03:06,040 --> 00:03:07,450 defined with the global keyword. 44 00:03:07,690 --> 00:03:13,960 That means it is referring to the same X that is a global variable defined outside of the function function 45 00:03:13,960 --> 00:03:14,200 one. 46 00:03:15,220 --> 00:03:16,970 So let us go for another example. 47 00:03:17,050 --> 00:03:22,540 There is a global and local biddable with the same name here you can find that it is going to fight 48 00:03:22,540 --> 00:03:26,170 is a global variable defined before the function function, too. 49 00:03:26,410 --> 00:03:29,980 And here we are defining another variable with the same name. 50 00:03:30,220 --> 00:03:33,190 But here it is having a local school. 51 00:03:33,400 --> 00:03:37,490 So local variables that access from the block where it is defined only. 52 00:03:37,780 --> 00:03:40,440 So here we have written this is the gluten. 53 00:03:40,630 --> 00:03:42,040 So print locally. 54 00:03:42,160 --> 00:03:45,180 If I print this value of a, I shall be getting 10 here. 55 00:03:45,580 --> 00:03:49,580 So before calling this function to I'm just printing the value of it. 56 00:03:49,600 --> 00:03:51,760 That is a globally I'm expecting here. 57 00:03:51,760 --> 00:03:57,550 The value of it will get printed as five and after this function to call if I print the value of it, 58 00:03:57,580 --> 00:04:01,990 there is a globally I'm supposed to get the value five here back again. 59 00:04:02,230 --> 00:04:05,710 But within this particular function, two point, I shall print this locally. 60 00:04:05,980 --> 00:04:08,310 I'm supposed to get the value estin. 61 00:04:08,500 --> 00:04:12,400 So according to our expectation, you are getting the outcome as well. 62 00:04:13,090 --> 00:04:17,680 Let us go for another one where it will be creating and using non-local variables. 63 00:04:18,190 --> 00:04:21,430 So we're here to a different one function within the function. 64 00:04:21,430 --> 00:04:22,690 One variable is defined. 65 00:04:23,500 --> 00:04:26,340 This variable is locally within the function itself. 66 00:04:27,160 --> 00:04:31,000 That means this variable is having the scope within the function itself. 67 00:04:31,420 --> 00:04:33,790 So now here we are having a nested function. 68 00:04:34,090 --> 00:04:39,980 So within the nested function, the name of the function is not supposed to define non-local variables. 69 00:04:40,300 --> 00:04:43,030 So here you can find that we have defined nonlocal X. 70 00:04:43,330 --> 00:04:48,090 That means where referring the same X, which is defined here because it is nonlocal here. 71 00:04:48,370 --> 00:04:54,300 So X has got uprated and from the inner from the inner method printing the value of X. 72 00:04:54,460 --> 00:05:00,010 So we are expecting that X will get printed as nonlocal when executing this in our method. 73 00:05:00,040 --> 00:05:04,950 So this code will get executed, X will get updated with the new string that is the nonlocal. 74 00:05:05,170 --> 00:05:11,260 So after after executing this inner method, if I print this X, so we are expecting that we are supposed 75 00:05:11,260 --> 00:05:17,350 to get nonlocal here and here you are executing the order method after completion of the definition 76 00:05:17,350 --> 00:05:19,190 of the outer function here. 77 00:05:19,660 --> 00:05:21,250 So inner nonlocal. 78 00:05:21,280 --> 00:05:26,830 So from here, when we are printing the value of X, so X has got just initialized with the string nonlocal. 79 00:05:27,100 --> 00:05:31,750 So inner colon nonlocal is coming, but as X is a nonlocal available. 80 00:05:31,930 --> 00:05:37,350 So as a result of that, this X will also get updated with the string nonlocal. 81 00:05:37,690 --> 00:05:43,300 So as a result of that, this outer colon, outer colon X will also print nonlocal here. 82 00:05:43,810 --> 00:05:50,500 But in that same code, if I make this line, only if I make this line under comment, then we are having 83 00:05:50,600 --> 00:05:52,660 this one as X is equal to nonlocal. 84 00:05:52,930 --> 00:05:59,060 So as this particular variable has gotten has got defined not without the nonlocal keyword. 85 00:05:59,230 --> 00:06:04,390 So as a result of that, its scope will be local within the innot method only. 86 00:06:04,600 --> 00:06:11,580 So that's why it do not update this global X, it will just update that local X only within this inner 87 00:06:11,590 --> 00:06:11,980 method. 88 00:06:12,220 --> 00:06:13,960 So what will happen inertly? 89 00:06:14,050 --> 00:06:17,760 Print nonlocal from the inner button will be printing this out. 90 00:06:17,860 --> 00:06:18,550 Colonics. 91 00:06:18,730 --> 00:06:21,420 It will print the string back again. 92 00:06:21,430 --> 00:06:24,910 You can find that it is printing, nonlocal and local. 93 00:06:25,240 --> 00:06:30,670 So in this video we have discussed the what is nonlocal variable, what is global variable, how to 94 00:06:30,670 --> 00:06:36,220 define nonlocal variable, how to define global variable into details and with demonstration. 95 00:06:36,870 --> 00:06:38,170 Thanks for watching this video.