Quantcast
Channel: Web development / Programming
Viewing all articles
Browse latest Browse all 52

Global Variable Inside A Function?

$
0
0
Hello Everyone,

Can anyone tell me how to set a global variable inside a function in python? Also, check the below code or anyone knows the better way to learn python in depth. Any recommendation on below code is it right or not.

globvar = 0
def set_globvar_to_one():
global globvar # Needed to modify global copy of globvar
globvar = 1
def print_globvar():
print globvar # No need for global declaration to read value of globvar
set_globvar_to_one()
print_globvar() #...

Global Variable Inside A Function?

Viewing all articles
Browse latest Browse all 52

Trending Articles