1#it is best not to use global variables in a function
2#(pass it as an argument)
3a = 'This is global a'
4def yourFunction():
5 global a
6 return a[0:2]
1#A global variable can be accessed from any function or method.
2#However, we must declare that we are using the global version and not the local one.
3#To do this, at the start of your function/method write "global" and then the name of the variable.
4#Example:
5myVariable = 1
6
7def myFunction():
8 global myVariable
9 print(myVariable)
10
11myFunction()
1a = input('Hello: ')
2if a == 'world':
3 global b
4 b = input('Here')
5print b
6#Prints the input for be as a result