पायथन जी स्थानीय कीवर्ड
उदाहरण
किसी फ़ंक्शन के अंदर एक वैश्विक चर घोषित करें, और इसे फ़ंक्शन के बाहर उपयोग करें:
#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)
परिभाषा और उपयोग
कीवर्ड का global
उपयोग गैर-वैश्विक दायरे से वैश्विक चर बनाने के लिए किया जाता है, उदाहरण के लिए किसी फ़ंक्शन के अंदर।