Biton Global QAD.
So we know that we are having made the booth few words that are available in Python, but in this video
we are concentrating only on the global keyword.
A Python programs global keyword allows us to modify the variable outside of the court in scope so we
can we can change the variable value outside of the current scope.
And it is used to create a global biddable and make changes to the biddable in the local context also.
So how do we use the global keyword when we create a variable inside a function?
It's local is by default.
The scope is local.
By default.
When we define a variable outside of the function, it is global.
By default, you don't have to use the global keyword.
In that case.
So we use the global key word to read and write a global variable inside a function.
Use a global keyword outside of the function has got no effect.
So if anybody were defining one variable outside of the function by default, it is having the global
scope.
Whenever we are defining one variable within the function, it is having the local scope.
But whenever this is that this is the third point is very interesting.
We use a global key word to read and write a global variable inside or from the function itself.
So I think for the better idea, let us go for one practical demonstration to show you that how does
Global QAD can be can be playing a magic in about Scob definition of a variable in this demonstration?
We have defined one function that is a function.
One word, one variable has got defined and initialize with the veloute 20.
Within this function is variable.
X is having the header 20 here.
We're having one nested function within function one.
The nested function is having the name function.
Here you have defined one variable X and with the key word global.
So global X actually the global keyword will be used to modify a global variable.
Here the X value has got updated with developed 25 here.
So this X is a global one.
So here you have defined one variable.
We just up the scope globally.
So now before calling this function two, we are printing the value of X are calling the function two
now and we are called a function two.
And then after calling function two, the value of X is getting printed.
So now let us see what is the outcome.
We are going to have.
So here you see here this X is having the value.
Twenty calling function two now after calling function to the value of X has still with the value 20.
Because the changes we are not going to get here.
We are expecting that the value might be changing, but no changes at all.
Is the X has got printed with the value twenty before and after calling the function to.
Because this particular X is having the global scope.
So if we have if we want to print this particular X, then after calling this function one, we can
directly print this X because this particular X is having the global scope.
That is not within this function to our function.
One, it is outside of that.
So anybody you are trying to print the value of X from the from the outside of this function one, then
we are getting this value as 25.
I think you are getting this idea, this particular global X is actually we are defining one variable
X, which is having the global scope that we going to define a global variable and that global variable
is getting updated, are getting getting initialized with the value.
Twenty five here.
So this X and this X, they're actually corresponding to this X.
So this X is still with the value.
20.
So that's right.
We've got the output that's 20.
And in the global X, the value of X has become 25 here.
I think you got the idea.
What is the purpose of this global keyword usage in this line to define one global variable and to model
with the help of the global keyword?
Thanks for watching this video.