I am nothing, no one, nobody, no more

Get out of life alive le blog de SnippyHolloW.

Pass-by-value/ref.

Copy-pasted from http://www.testingreflections.com/node/view/5126

C is pass-by-value

Straightforward. You can simulate pass-by-reference with pointers. Not much else to say here.

Java is pass-by-value

Primitive Types (non-object built-in types) are simply passed by value. Passing Object References feels like pass-by-reference, but it isn’t. What you are really doing is passing references-to-objects by value.

OK, so what about Python?

Python passes references-to-objects by value (like Java), and everything in Python is an object. This sounds simple, but then you will notice that some data types seem to exhibit pass-by-value characteristics, while others seem to act like pass-by-reference… what’s the deal?

It is important to understand mutable and immutable objects. Some objects, like strings, tuples, and numbers, are immutable. Altering them inside a function/method will create a new instance and the original instance outside the function/method is not changed. Other objects, like lists and dictionaries are mutable, which means you can change the object in-place. Therefore, altering an object inside a function/method will also change the original object outside.