Can Python function return multiple data?

Michael Torrie torriem at gmail.com
Thu Jun 4 10:16:58 EDT 2015


On 06/03/2015 04:28 PM, sohcahtoa82 at gmail.com wrote:

> 
> People actually argue that Python passes by value?  This is easily
> proven wrong by passing a mutable object to a function and changing
> it within the function.

Sure but if you reassign the variable that was passed it, it has no
effect whatsoever on the caller's variable, mutable or not.  This is why
people argue for "pass by value."  Because of this confusion, we often
say, "pass by object."

For example

def foo(bar):
    bar.append(5)
    bar = 6 #bar is no longer referring to a list

a=[1,2,3,4]
foo(a)
print (a)
# prints [1,2,3,4,5]









More information about the Python-list mailing list