#Call by value
def change(x,y):
x=x+5
y=y+10
print "In the function changes a&b is %d,%d"%(x,y)
a=10
b=20
print "\nBefore calling the function a&b is %d,%d"%(a,b)
change(a,b)
print "\nAfter calling a&b is %d,%d"%(a,b)
#program to swap(interchange) the two given variable.
def swap(x,y):
x=x+y
y=x-y
x=x-y
print "In swap function x=%d, y=%d"%(x,y)
return y,x
a=10
b=20
print "Before swap a=%d, b=%d"%(a,b)
print "\nAfter the calling the swap function, a=%d,b=%d"%swap(a,b)
#Call By Reference
def change (x,y):
x=x+5
y=y+10
print "In the function change a&b is %d %d"%(x,y)
return x,y
a=10
b=20
print "\nBefore calling the function a&b is %d %d"%(a,b)
print "After calling the function a&b is %d %d"%change(a,b)
#Program to swap(intercahnge) the value of variables.
a=10
b=20
print "\nBefore swap a=%d, b=%d"%(swap(a,b))
def swap(x,y):
x=x+y
y=x-y
x=x-y
print"\nIn swap function x=%d,y=%d"%(x,y)
return y,x
print "\nAfter calling swap function a=%d, b=%d"%(b,a)
#Program to interchange the value of variables using call by reference
def exchange(m,n):
t=m
m=n
n=t
return n,m
a,b=input("Enter two Numbers: ")
print "Before Exchange a=%d,b=%d"%(a,b)
print "After Exchange a=%d, b=%d"%(exchange(b,a))