Use global key word to reference outside global variables : Global « Language Basics « Python






Use global key word to reference outside global variables

Use global key word to reference outside global variables

X = 88          # global X

def func():
    global X
    X = 99      # global X: outside def

func()
print X         # prints 99


           
       








Related examples in the same category

1.Demonstrates global variablesDemonstrates global variables
2.Introducing globals()Introducing globals()
3.Global variables
4.Local and global Scoping example.Local and global Scoping example.