Global and local scope

Sir, I did not get " enclosures " in global and local scope of variables.
Can you please help me.

Hey @Sreshth123,
I would recommend you to watch this small video again, It’s very much clear in video itself.
Still let me try to explain…

There are scopes like - global scope and local scope.
If you a variable x in a global scope, and you try to access that same variable in global you will get no error.
But if the variable x in a global scope and you try to access that var in a local scope may be a different function, it would throw you an error because variables are limited to the local scope itself. to access that global element. Use global keyword before the variable.

The second example.
where the variable x was already inside a function which is a local scope in itself. In that case you won’t say that u want to access global var x, instead you will use keyword nonlocal before x, that would signify you want to access a variable that is outside this scope, but not in a global scope.

I know, this would look very vague to you, But I still recommend you to watch video again, and implement that piece of code on yourself for a better understanding.

Thanks :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.