making a global variable in python code example

Example 1: python global variables

global var1
var1 = 'whatever'

Example 2: global in python

a = 'this is a global variable'
def yourFunction(arg):
    #you need to declare a global variable, otherwise an error
    global a
    return a.split(' ')

Example 3: how to make variable global in python

global variable
variable = 'whatever'

Example 4: python local variables

'''Local variables are those that are defined in a block '''
a = 1 #This is NOT a local variable, this is a global variable
def add():
  b = 1 #This IS a local variable
  print(b)
add()
#If we tried to print(b) outside of the add() function, we would get an error

Example 5: how to declare global variable in python

global n
n = 'whatever'

Example 6: global python variablen

def f():
    global s
    print(s)
    s = "Zur Zeit nicht, aber Berlin ist auch toll!"
    print(s)
s = "Gibt es einen Kurs in Paris?" 
f()
print(s)