Q:

Change the Global value in Python

I have a global variable called "result"  and trying to change this value by calling a function . 
import sys 

def increment_result(a):
    for i in range(0,3):
        a += 1

result = 0
increment_result(result)
print(result)

But the result value is zero but expecting the result value to be 3.How can I change this global variable by using Pass by Reference in Python.

A:

Instead of trying to change global variable, return the changed value and reassign the return value back to the variable from the caller:
import sys 

def increment_result(a):
    for i in range(0,3):
        a += 1
    return a

result = 0
result = increment_result(result)
print(result)

If you really want to change global variable, you need to declare it using global statement:
def increment_result(a):
    global result  # <-- to access the global variable
    for i in range(0,3):
        a += 1
    result = a

