Python Local variables

Previous
Next

Local variables:

  • Defining a variable inside the function.
  • Local variables can be accessed only from the same function in which it has defined.
  • We access the local variable directly.
def test():
    a=10 #local
    print("Inside :",a)
    return

test()
print("Outside :",a) #error :

Arguments of a function:

  • Variables used to store input of the function.
  • Arguments are working like local variables.
  • Arguments can access within that function only.
def test(a, b): #a,b are local
    print("Inside :",a)
    print("Inside :",b)
    return

test(10,20)
print("Outside :",a) #error
Previous
Next

Add Comment

Courses Enquiry Form