Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Scope of Variables in Python

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 298
    Comment on it

    In Python variables in a program which may not be accessible at all locations in python program. This depends on where you have declared a variable and value.
    The scope of a variable determines the portion of the program using which we can access a particular identifier and variable. There are two basic scopes of variables in Python to given below
    Global variables-
    Local variables-
    And for example you can see below code-

    # Function definition is here
    def sum( arg1, arg2 ):
       # Add both the parameters and return them."
       total = arg1 + arg2; # Here total is local variable.
       print "Inside the function local total : ", total
       return total;
    # Now you can call sum function
    sum( 40, 60 );
    print "Outside the function global total : ", total 

    And output-
    Inside the function local total :100
    Outside the function global total :0

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: