Chapter 09 : Parameter Passing Methods

Example: 1, Page No.: 5.63

In [1]:
#Call By Value

def cube(x):
    x=x*x*x
    return(x)

n=5
print "Cube of %d is"%n,cube(n)
Cube of 5 is 125

Example: 2, Page No.:5.64

In [2]:
#Call by reference

def interchange(a,b):
    t=0
    t=a
    a=b
    b=t
    return b,a

    
i=5
j=10
print "i and j values before interchange:", i, j

i=10
j=5
interchange(i,j)

#Result
print "i and j values after interchange:",i,j

print "i and j avalues after interchange in the function : %d %d \n"%interchange(i,j)
i and j values before interchange: 5 10
i and j values after interchange: 10 5
i and j avalues after interchange in the function : 10 5