Python in space and scope.
Namespace in Python, in Python namespace is a collection of names which holds as a mapping of every
name which you have defined the corresponding objects so objects will have different names and these
names will be defined in some namespace.
So different names, spaces can coexist at a given time, but completely they are completely isolated
in namespace containing all the building names.
It is created when you start the python interpreter and exists as long as we don't exit from the environment.
So namespace in Python can be can be drawn there can be explained using these respective Degner so modules
can have various functions and classes, a local namespace is created when the function is called,
which has all the names defined in it.
Similarly is the case with the class also.
So just sinisi here, when having one namespace, there's a function, local namespace with all the
variables, all the objects, whatever we have defined in this particular function.
So they'll be mapped here and then we're having this model global namespace and this is this particular
function.
Local namespace will be the part of this.
And then we're having that building namespace for the respective application in execution.
So I think for the better understanding, let us look for a practical demonstration where you will be
showing you that how this namespace can be used in Python.
So here is the demonstration identifier.
It is nothing but one name, which is simply a name given to Python objects, and we can get the address
in RAM of some object through the building function.
That is our ID.
So using this ID function, we can easily get the ID of the respective identifier.
So now you can get the different versions of ID in our execution, whatever.
Already we have written here under the command.
So it is legal to do so.
I want to print the idea of two.
I want to print the idea of E also.
So see what we're doing.
So here is the outcome.
So the idea up to an idea of a board are some.
You can easily find that book.
Aasim, if anybody is sending a signal to and we're trying to print the idea of a we are finding that
one, this ID is also the same as we had before.
Next one is that we have made is equal to a plus one.
So it is now holding the value three here.
So if we print the idea of eight, we're finding that the idea of A has got different and it is the
ID, which is different from the idea of a whatever.
We got the outcome earlier.
Next idea of three, if I print this idea up three, I'm getting this one as one seven six four five
one six zero six four.
So that means it is the same as the idea of it because it is done holding the value through here.
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
in case of a I think of two when it was having the value to here.
So if I print that aspect, one, if I go on printing.
They print.
So if I can find that the idea of to an idea of being water bothersome because basically two has been
asked, so in this way we've discussed that what is identified and what is an ID idea starting but one
building function available in Python to bring their respective memory address in the realm.
The addresses, whatever were printed, if we execute the same code, we might be getting some different
ideas.
So that will be decided by that during the execution of my code, which will block is free.
And depending upon that, the memory allocation against variables will be done by the system.
Next one is ESCAP.
So we are having this outer function where having this inner function, so it is also known as nested
function, so globally that means I'm defining one variable within outer function, but the scope will
be global.
So that's why you abuse the key word global here.
This valuable AI has been initialized with 20.
Now, that is my inner function.
There's a nested function which is existing inside the outer one.
You can look at the indentation and you can get the idea that this particular inner function is within
the outer function here defining this.
But it is not a new way, but it is a globally, which you referred earlier, that it has got updated
with the value of thirty and the value of it has got printed from the outer function, this inner function,
whatever it was defined just now, it has got executed, it has been called so during execution it will
have its execution and we are printing this value up a uprate exiting from the inner function within
our function.
So I'm reading this is the routine at first.
So that is the eight is there.
I'm printing the value of it.
So it is printing then.
Now we calling this outer function.
So when the control will be going to the outer function, this is actually the globally.
That means that E which is right now holding the value chain.
So that then has got up to 20, but we didn't print anything then the inner function will be called.
So inner function is also defined the same global variable eight.
So this is available in the global scope and that it will be used in the inner function.
Now eight is 30.
Now this city is operating the global in scope, the eight which is defined in the global scope.
Now we are printing the value of it.
So it is printing 30 year after calling the Zener function again, we are printing this value of from
the outer function.
Then it is printing 30 and after calling this outer function, if you print the value of it here, I'm
getting 30 back again.
So it is the it is giving me the idea, it is giving us the idea.
What is the scope here?
And whenever one variable is in one scope, then how to access that variable from some inner scope using
the global keyword as we did in our coding in this demonstration, we have discussed that how to define
what is happening whenever we are defining one identified in our python coding.
Thanks for watching this video.