global and local variable in python by R4R Team

What is global variable ?

- A variable whose scope are in the entire program or which can be excess anywhere in the program are call global varibale

What is local variable ?

- A variable whose scope is limited to some specific region or some areas and which can not excessed by entire program.

In python for excess the global variable inside the function body ,it provide the 'global' keyword like global variable

program -

#global variable
a="global variable"

def function():
b="Local variable"
print(b)
# for excess the global variable
global a
print(a)

function()


output -

Local variable
global variable


- In this program , we make two variable , one of them are global which is outside the function and another is local variable which is inside the function. so for calling the global variable we use global keyword otherwise it will give error that undefined symbol

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!