1"""
2USING GLOBALS ARE A BAD IDEA, THE BEST WAY TO PERFORM AN ACTION WHICH NEEDS GLOBALS WOULD
3BE TO USE RETURN STATEMENTS. GLOBALS SHOULD ONLY EVER BE USED IN RARE OCCASIONS WHEN YOU
4NEED THEM
5"""
6
7# allows you to modify a variable outside its class or function
8
9EXAMPLE:
10
11def test_function():
12 global x
13 x = 10
14
15test_function()
16print(f"x is equal to {x}") # returns x is equal to 10
17
1a = 'this is a global variable'
2def yourFunction(arg):
3 #you need to declare a global variable, otherwise an error
4 global a
5 return a.split(' ')
6
1x = 5
2
3def foo():
4 global x = 10
5 print("local x:", x)
6
7
8foo()
9print("global x:", x)
1a = input('Hello: ')
2if a == 'world':
3 global b
4 b = input('Here')
5print b
6#Prints the input for be as a result
1def Takenin():
2 global ans
3 ans = "This is the coorect way to do it"
4
5def Return():
6 Takenin()
7 print(f"ans :{ans}")