Python g lobal Sleutelwoord
Voorbeeld
Verklaar 'n globale veranderlike binne 'n funksie, en gebruik dit buite die funksie:
#create a function:
def myfunction():
global x
x =
"hello"
#execute the function:
myfunction()
#x should now
be global, and accessible in the global scope.
print(x)
Definisie en gebruik
Die global
sleutelwoord word gebruik om globale veranderlikes vanuit 'n nie-globale omvang te skep, bv binne 'n funksie.