Hello everyone!
Let us learn about the type of python variables with an example.
Types of Python Variables :-
1} Local Variable :
The variables that are declared within the function and have scope within the function are known as local variables.
- Example -
def add():
a=20
b=30
print ("The sum is", c)
add()
~ Output: The sum is 50.
2} Global Variable :
The variables that are declared outside the function serves as global variable.
They can be used inside or outside the function.
- Example -
x=|0|
def main function ():
global x
print (x)
x='Welcome'
print (x)
main function
print (x)
~ Output:
|0|
Welcome
Welcome