MENU
Question -

Write a program to illustrate тАЬPass by refe-rence vs valueтАЭ



Answer -

#!/usr/bin/python # Function definition is here
def changeme(mylist): тАЬThis changes a passed list into this functionтАЭ
mylist.append([l,2,3,4]);
print тАЬValues inside the function: тАЬ, mylist
return # Now you can call changeme
function mylist=[10,20,30];
changeme(mylist);
print тАЬValues outside the function: тАЬ, mylist
It produce following result:
Values inside the function: [10, 20,30, [1,2,3,4]]
Values outside the function: [10,20, 30, [1,2,3,4]]

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×