a = 'this is a global variable' def yourFunction(arg): #you need to declare a global variable, otherwise an error global a return a.split(' ')
#it is best not to use global variables in a function #(pass it as an argument) a = 'This is global a' def yourFunction(): global a return a[0:2]
a = 0 def testFor(): global a if(a == 0): #run code
"allows you to modify a variable outside its class or function"
x = 5 def foo(): global x = 10 print("local x:", x) foo() print("global x:", x)
global x x=1
a = input('Hello: ') if a == 'world': global b b = input('Here') print b #Prints the input for be as a result
globals 1, 2, 3