0

What is the difference between local and global variable?

Please help me for my improvement. I want to know about the use, difference and working procedure of local and global variable.

6th Sep 2020, 12:15 PM
Ridowan Ahmed
Ridowan Ahmed - avatar
2 odpowiedzi
+ 4
Just for clarification, in Python, local is function scoped only. Block scoped is not supported in Python. In many other languages, local can be applied at both the function and block scoped.
6th Sep 2020, 1:33 PM
David Carroll
David Carroll - avatar
0
Global variables are those which are available in entire program, so you use those anywhere in Program.. And until those overhidden by local variables.. Local variables are those which exists in that block in which it is declared.. Just example: In C, int i = 10; //global variable. int main() { int j =9; //local variable, not exist outside main function ... } //use of j error here but use of i is valid In python, Num = 5 #called global but restricted to use directly in functions, means you have add globals to functions slight different with other languagees, as added explanation, below by @David Carroll. def fun() : Num=2 //local to fun function, global Num is not present and different, to accept write=> global Num Edit: A samples only, not exactly because it may* change according to code addition, but if share how much you know, where you need clarifications for any perticular, then you can better accurate answers....
6th Sep 2020, 1:16 PM
Jayakrishna 🇮🇳