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
    • 335
    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-

    1. # Function definition is here
    2. def sum( arg1, arg2 ):
    3. # Add both the parameters and return them."
    4. total = arg1 + arg2; # Here total is local variable.
    5. print "Inside the function local total : ", total
    6. return total;
    7. # Now you can call sum function
    8. sum( 40, 60 );
    9. 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
Reset Password
Fill out the form below and reset your password: