1 00:00:00,750 --> 00:00:02,910 Python in space and scope. 2 00:00:04,440 --> 00:00:11,040 Namespace in Python, in Python namespace is a collection of names which holds as a mapping of every 3 00:00:11,040 --> 00:00:16,950 name which you have defined the corresponding objects so objects will have different names and these 4 00:00:16,950 --> 00:00:19,560 names will be defined in some namespace. 5 00:00:20,070 --> 00:00:28,230 So different names, spaces can coexist at a given time, but completely they are completely isolated 6 00:00:28,620 --> 00:00:31,320 in namespace containing all the building names. 7 00:00:31,560 --> 00:00:39,690 It is created when you start the python interpreter and exists as long as we don't exit from the environment. 8 00:00:41,520 --> 00:00:49,350 So namespace in Python can be can be drawn there can be explained using these respective Degner so modules 9 00:00:49,350 --> 00:00:55,530 can have various functions and classes, a local namespace is created when the function is called, 10 00:00:56,250 --> 00:00:58,650 which has all the names defined in it. 11 00:00:59,160 --> 00:01:02,100 Similarly is the case with the class also. 12 00:01:02,250 --> 00:01:09,210 So just sinisi here, when having one namespace, there's a function, local namespace with all the 13 00:01:09,210 --> 00:01:13,010 variables, all the objects, whatever we have defined in this particular function. 14 00:01:13,350 --> 00:01:19,980 So they'll be mapped here and then we're having this model global namespace and this is this particular 15 00:01:19,980 --> 00:01:20,430 function. 16 00:01:20,430 --> 00:01:22,560 Local namespace will be the part of this. 17 00:01:22,770 --> 00:01:27,770 And then we're having that building namespace for the respective application in execution. 18 00:01:28,290 --> 00:01:32,490 So I think for the better understanding, let us look for a practical demonstration where you will be 19 00:01:32,490 --> 00:01:35,910 showing you that how this namespace can be used in Python. 20 00:01:36,150 --> 00:01:39,930 So here is the demonstration identifier. 21 00:01:39,930 --> 00:01:47,220 It is nothing but one name, which is simply a name given to Python objects, and we can get the address 22 00:01:47,220 --> 00:01:51,210 in RAM of some object through the building function. 23 00:01:51,210 --> 00:01:52,170 That is our ID. 24 00:01:52,440 --> 00:01:57,660 So using this ID function, we can easily get the ID of the respective identifier. 25 00:01:58,260 --> 00:02:03,490 So now you can get the different versions of ID in our execution, whatever. 26 00:02:03,630 --> 00:02:05,950 Already we have written here under the command. 27 00:02:06,450 --> 00:02:08,640 So it is legal to do so. 28 00:02:08,640 --> 00:02:10,290 I want to print the idea of two. 29 00:02:10,290 --> 00:02:12,360 I want to print the idea of E also. 30 00:02:12,570 --> 00:02:13,880 So see what we're doing. 31 00:02:14,970 --> 00:02:16,220 So here is the outcome. 32 00:02:16,800 --> 00:02:21,180 So the idea up to an idea of a board are some. 33 00:02:21,180 --> 00:02:22,560 You can easily find that book. 34 00:02:22,560 --> 00:02:28,770 Aasim, if anybody is sending a signal to and we're trying to print the idea of a we are finding that 35 00:02:28,770 --> 00:02:32,370 one, this ID is also the same as we had before. 36 00:02:32,700 --> 00:02:35,270 Next one is that we have made is equal to a plus one. 37 00:02:35,280 --> 00:02:37,750 So it is now holding the value three here. 38 00:02:38,190 --> 00:02:43,860 So if we print the idea of eight, we're finding that the idea of A has got different and it is the 39 00:02:43,860 --> 00:02:46,800 ID, which is different from the idea of a whatever. 40 00:02:46,800 --> 00:02:49,520 We got the outcome earlier. 41 00:02:50,100 --> 00:02:56,040 Next idea of three, if I print this idea up three, I'm getting this one as one seven six four five 42 00:02:56,040 --> 00:02:57,230 one six zero six four. 43 00:02:57,480 --> 00:03:02,930 So that means it is the same as the idea of it because it is done holding the value through here. 44 00:03:03,690 --> 00:03:09,990 If I say and B is two and if I want to print the idea of two are getting the same idea which you had 45 00:03:10,230 --> 00:03:14,430 in case of a I think of two when it was having the value to here. 46 00:03:15,390 --> 00:03:18,240 So if I print that aspect, one, if I go on printing. 47 00:03:19,140 --> 00:03:19,950 They print. 48 00:03:22,690 --> 00:03:30,640 So if I can find that the idea of to an idea of being water bothersome because basically two has been 49 00:03:30,640 --> 00:03:38,470 asked, so in this way we've discussed that what is identified and what is an ID idea starting but one 50 00:03:38,470 --> 00:03:44,500 building function available in Python to bring their respective memory address in the realm. 51 00:03:45,490 --> 00:03:49,780 The addresses, whatever were printed, if we execute the same code, we might be getting some different 52 00:03:49,780 --> 00:03:50,090 ideas. 53 00:03:50,090 --> 00:03:56,050 So that will be decided by that during the execution of my code, which will block is free. 54 00:03:56,260 --> 00:04:02,340 And depending upon that, the memory allocation against variables will be done by the system. 55 00:04:03,370 --> 00:04:04,470 Next one is ESCAP. 56 00:04:05,270 --> 00:04:10,250 So we are having this outer function where having this inner function, so it is also known as nested 57 00:04:10,250 --> 00:04:16,280 function, so globally that means I'm defining one variable within outer function, but the scope will 58 00:04:16,280 --> 00:04:16,920 be global. 59 00:04:17,120 --> 00:04:19,370 So that's why you abuse the key word global here. 60 00:04:20,030 --> 00:04:22,650 This valuable AI has been initialized with 20. 61 00:04:23,300 --> 00:04:24,890 Now, that is my inner function. 62 00:04:25,040 --> 00:04:28,600 There's a nested function which is existing inside the outer one. 63 00:04:29,000 --> 00:04:34,130 You can look at the indentation and you can get the idea that this particular inner function is within 64 00:04:34,130 --> 00:04:36,710 the outer function here defining this. 65 00:04:36,920 --> 00:04:42,890 But it is not a new way, but it is a globally, which you referred earlier, that it has got updated 66 00:04:42,890 --> 00:04:48,920 with the value of thirty and the value of it has got printed from the outer function, this inner function, 67 00:04:48,920 --> 00:04:54,560 whatever it was defined just now, it has got executed, it has been called so during execution it will 68 00:04:54,560 --> 00:05:00,950 have its execution and we are printing this value up a uprate exiting from the inner function within 69 00:05:01,280 --> 00:05:02,140 our function. 70 00:05:02,900 --> 00:05:05,110 So I'm reading this is the routine at first. 71 00:05:05,540 --> 00:05:07,240 So that is the eight is there. 72 00:05:07,250 --> 00:05:08,860 I'm printing the value of it. 73 00:05:09,320 --> 00:05:10,660 So it is printing then. 74 00:05:11,060 --> 00:05:13,050 Now we calling this outer function. 75 00:05:13,070 --> 00:05:17,350 So when the control will be going to the outer function, this is actually the globally. 76 00:05:17,620 --> 00:05:20,180 That means that E which is right now holding the value chain. 77 00:05:20,720 --> 00:05:27,050 So that then has got up to 20, but we didn't print anything then the inner function will be called. 78 00:05:27,050 --> 00:05:30,850 So inner function is also defined the same global variable eight. 79 00:05:30,890 --> 00:05:36,360 So this is available in the global scope and that it will be used in the inner function. 80 00:05:36,950 --> 00:05:38,470 Now eight is 30. 81 00:05:38,480 --> 00:05:44,100 Now this city is operating the global in scope, the eight which is defined in the global scope. 82 00:05:44,300 --> 00:05:46,090 Now we are printing the value of it. 83 00:05:46,140 --> 00:05:51,740 So it is printing 30 year after calling the Zener function again, we are printing this value of from 84 00:05:51,740 --> 00:05:52,670 the outer function. 85 00:05:53,120 --> 00:05:58,880 Then it is printing 30 and after calling this outer function, if you print the value of it here, I'm 86 00:05:58,880 --> 00:06:00,310 getting 30 back again. 87 00:06:00,740 --> 00:06:04,960 So it is the it is giving me the idea, it is giving us the idea. 88 00:06:05,000 --> 00:06:06,610 What is the scope here? 89 00:06:06,950 --> 00:06:13,250 And whenever one variable is in one scope, then how to access that variable from some inner scope using 90 00:06:13,250 --> 00:06:19,700 the global keyword as we did in our coding in this demonstration, we have discussed that how to define 91 00:06:19,700 --> 00:06:23,970 what is happening whenever we are defining one identified in our python coding. 92 00:06:24,640 --> 00:06:25,880 Thanks for watching this video.