newbie questions

Adam DePrince adam at
Mon Dec 13 20:03:54 CET 2004

On Mon, 2004-12-13 at 11:30, houbahop -->
> thanks, very usefull answer.
> > Immutable types (e.g. strings, numbers, tuples) are generally returned 
> > directly from functions, rather than returned as 'output parameters'. The 
> > ability to return multiple values easily (via "return a, b, c" & "x, y, z 
> > = myfunc()" generally eliminates the need for 'by reference' output 
> > parameters as used by C, C++, Java and the like.
> > P.S. If you *really*, *really*, *really* want to fake output parameters, 
> > just wrap them in a list:
>  return multiple values is ok, I usualy use a function only to return one 
> value, for exemple : value=IsSomething(), returning true, to include that in 
> an if statement : if (isSomething(blabla) ) ... but It's not a problem to 
> change that habit. and as I have read somewhere about python : "Explicit is 
> better than implicit"
> Dominique.

I think your interpretation of the the "explicit vs. implicit" quote
might be confusing in this case.  Certainly:

x = 0 
def a():
	something = 1
	somethingelse = 2
	global x
	x = something
	return somethingelse

y = a()
print x,y 

To say "we are explicitly setting X" in a is wrong.  We are returning 1
and 2.  We return 2 explicitly.  We return 1 by side effect.  

If we want to explicitly return both, then:

def a():
	something = 1
	somethingelse = 2 
	return something,somethingelse

x,y = a()

This makes the code clear and easy to understand.  

Navré je ne pas répondre en français.

- Adam DePrince

More information about the Python-list mailing list