Call By Value Vs. Call By Reference

Post Reply
AyubHussain
Posts: 138
Joined: Fri Nov 23, 2018 2:48 am

Call By Value Vs. Call By Reference

Post by AyubHussain » Mon Dec 03, 2018 10:46 am

What Is “Call By Value” In Python & What Is “Call By Reference” In Python?

ramya
Posts: 89
Joined: Fri Nov 23, 2018 2:55 am

Re: Call By Value Vs. Call By Reference

Post by ramya » Mon Dec 03, 2018 10:47 am

Call By Value :

In call-by-value, the argument whether an expression or a value gets bound to the respective variable in the function.

Python will treat that variable as local in the function-level scope. Any changes made to that variable will remain local and will not reflect outside the function.

Call By Reference :

We use both “call-by-reference” and “pass-by-reference” interchangeably. When we pass an argument by reference, then it is available as an implicit reference to the function, rather than a simple copy. In such a case, any modification to the argument will also be visible to the caller.

This scheme also has an advantage of bringing more time and space efficiency because it leaves the need of creating local copies.

On the contrary, the disadvantage could be that a variable can get changed accidentally during a function call. Hence, the programmers need to handle in the code to avoid such uncertainty.

Post Reply

Return to “Python Functions”