The concept of local variable in Python is same as in other programming languages. When a variable is declared inside a function, the scope of the variable is restricted within that function and it cannot be accessible outside. Even while declaring the variables, the local variable can have the same name as global variables. the local variable takes the priority in that case.
------------------------------------
def value_change(var):
var = var + 100
print ("Value of var in the function is",var)
var = 100
value_change(var)
print ("Value of var after the function call is", var)
------------------------------------
The output of the above program shall be
Value of var in the function is 200
Value of var after the function call is 100
0 Comments