call by value in python by R4R Team

Call by value-
- call by value is a concept in which we call a function and pass the value of the variable not the refence of the variable.


program-

def function(l):
for i in range(len(l)):
l[i]=0
print("list inside function",l)

print("Enter number in list")
l=list(map(int,input().split()))
print("Given List is",l)
function(list(l))
print("List after function calling",l)


output-

Enter number in list
1 2 3 4 5
Given List is [1, 2, 3, 4, 5]
list inside function [0, 0, 0, 0, 0]
List after function calling [1, 2, 3, 4, 5]


-In this program, we take a input of list and pass in the function by 'call by value' concept and change the content of the list inside function do not reflect the change in actual list as shown in above program and output.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!