1globvar = 0
2
3def set_globvar_to_one():
4 global globvar # Needed to modify global copy of globvar
5 globvar = 1
6
7def print_globvar():
8 print(globvar) # No need for global declaration to read value of globvar
9
10set_globvar_to_one()
11print_globvar() # Prints 1
1#it is best not to use global variables in a function
2#(pass it as an argument)
3a = 'This is global a'
4def yourFunction():
5 global a
6 return a[0:2]