Global Variables:
Global variables are the one that is defined and declared outside a function and we need to use them inside a function. This means that a global variable can be accessed inside or outside of the function.
Example:
a = "Hello World!!"
def func_1():
print(a)
func_1()
Output: Hello World!!
Local Variables:
Local variables are declared inside the function's body or in the local scope is known as a local variable.
Example:
def func_1():
a = "Hello!!"
print(a)
func_1()
Output: Hello!!
- Log in to post comments