1 00:00:00,490 --> 00:00:02,010 Biton Global QAD. 2 00:00:02,490 --> 00:00:07,380 So we know that we are having made the booth few words that are available in Python, but in this video 3 00:00:07,410 --> 00:00:10,410 we are concentrating only on the global keyword. 4 00:00:11,010 --> 00:00:18,930 A Python programs global keyword allows us to modify the variable outside of the court in scope so we 5 00:00:18,930 --> 00:00:22,750 can we can change the variable value outside of the current scope. 6 00:00:23,040 --> 00:00:30,150 And it is used to create a global biddable and make changes to the biddable in the local context also. 7 00:00:30,840 --> 00:00:35,940 So how do we use the global keyword when we create a variable inside a function? 8 00:00:36,060 --> 00:00:38,100 It's local is by default. 9 00:00:38,280 --> 00:00:39,350 The scope is local. 10 00:00:39,390 --> 00:00:40,020 By default. 11 00:00:40,440 --> 00:00:44,160 When we define a variable outside of the function, it is global. 12 00:00:44,220 --> 00:00:48,400 By default, you don't have to use the global keyword. 13 00:00:48,810 --> 00:00:49,550 In that case. 14 00:00:49,980 --> 00:00:56,280 So we use the global key word to read and write a global variable inside a function. 15 00:00:57,240 --> 00:01:01,440 Use a global keyword outside of the function has got no effect. 16 00:01:01,800 --> 00:01:06,780 So if anybody were defining one variable outside of the function by default, it is having the global 17 00:01:06,780 --> 00:01:07,260 scope. 18 00:01:07,620 --> 00:01:11,770 Whenever we are defining one variable within the function, it is having the local scope. 19 00:01:12,240 --> 00:01:15,610 But whenever this is that this is the third point is very interesting. 20 00:01:15,840 --> 00:01:22,950 We use a global key word to read and write a global variable inside or from the function itself. 21 00:01:23,250 --> 00:01:28,230 So I think for the better idea, let us go for one practical demonstration to show you that how does 22 00:01:28,230 --> 00:01:36,660 Global QAD can be can be playing a magic in about Scob definition of a variable in this demonstration? 23 00:01:36,690 --> 00:01:39,120 We have defined one function that is a function. 24 00:01:39,120 --> 00:01:43,740 One word, one variable has got defined and initialize with the veloute 20. 25 00:01:44,400 --> 00:01:45,930 Within this function is variable. 26 00:01:45,990 --> 00:01:47,810 X is having the header 20 here. 27 00:01:48,430 --> 00:01:51,540 We're having one nested function within function one. 28 00:01:51,920 --> 00:01:53,880 The nested function is having the name function. 29 00:01:54,660 --> 00:01:58,570 Here you have defined one variable X and with the key word global. 30 00:01:58,620 --> 00:02:04,260 So global X actually the global keyword will be used to modify a global variable. 31 00:02:04,860 --> 00:02:08,440 Here the X value has got updated with developed 25 here. 32 00:02:08,910 --> 00:02:10,740 So this X is a global one. 33 00:02:10,770 --> 00:02:12,480 So here you have defined one variable. 34 00:02:12,720 --> 00:02:14,930 We just up the scope globally. 35 00:02:15,240 --> 00:02:21,210 So now before calling this function two, we are printing the value of X are calling the function two 36 00:02:21,210 --> 00:02:23,330 now and we are called a function two. 37 00:02:23,640 --> 00:02:27,900 And then after calling function two, the value of X is getting printed. 38 00:02:28,290 --> 00:02:30,360 So now let us see what is the outcome. 39 00:02:30,390 --> 00:02:31,110 We are going to have. 40 00:02:31,770 --> 00:02:34,660 So here you see here this X is having the value. 41 00:02:34,690 --> 00:02:41,100 Twenty calling function two now after calling function to the value of X has still with the value 20. 42 00:02:41,580 --> 00:02:43,890 Because the changes we are not going to get here. 43 00:02:44,370 --> 00:02:48,330 We are expecting that the value might be changing, but no changes at all. 44 00:02:48,330 --> 00:02:53,330 Is the X has got printed with the value twenty before and after calling the function to. 45 00:02:53,820 --> 00:02:56,910 Because this particular X is having the global scope. 46 00:02:57,270 --> 00:03:03,090 So if we have if we want to print this particular X, then after calling this function one, we can 47 00:03:03,090 --> 00:03:07,260 directly print this X because this particular X is having the global scope. 48 00:03:07,530 --> 00:03:09,960 That is not within this function to our function. 49 00:03:09,960 --> 00:03:11,610 One, it is outside of that. 50 00:03:11,820 --> 00:03:17,970 So anybody you are trying to print the value of X from the from the outside of this function one, then 51 00:03:17,970 --> 00:03:20,130 we are getting this value as 25. 52 00:03:20,550 --> 00:03:25,680 I think you are getting this idea, this particular global X is actually we are defining one variable 53 00:03:25,770 --> 00:03:33,570 X, which is having the global scope that we going to define a global variable and that global variable 54 00:03:33,600 --> 00:03:36,840 is getting updated, are getting getting initialized with the value. 55 00:03:37,090 --> 00:03:37,920 Twenty five here. 56 00:03:38,310 --> 00:03:42,000 So this X and this X, they're actually corresponding to this X. 57 00:03:42,330 --> 00:03:43,850 So this X is still with the value. 58 00:03:44,120 --> 00:03:44,520 20. 59 00:03:44,850 --> 00:03:45,430 So that's right. 60 00:03:45,460 --> 00:03:47,100 We've got the output that's 20. 61 00:03:47,400 --> 00:03:51,530 And in the global X, the value of X has become 25 here. 62 00:03:51,930 --> 00:03:53,580 I think you got the idea. 63 00:03:53,820 --> 00:04:00,410 What is the purpose of this global keyword usage in this line to define one global variable and to model 64 00:04:00,630 --> 00:04:02,250 with the help of the global keyword? 65 00:04:02,820 --> 00:04:04,020 Thanks for watching this video.