A new to Python question

Bernd Nawothnig Bernd.Nawothnig at t-online.de
Sat May 14 14:38:26 EDT 2005


> On 2005-05-14, M.E.Farmer wrote:

> (x,y,dotp,sumx,maxv) = abc(x,y,dotp,sumx,maxv)
> This will only create a tuple in memory that has no name to reference
> it by!

Maybe. But it does not seem to hurt. And I am not sure the tupel _is_
really created in that situation.

> How would you access the returned value?
> If you want a tuple you need to assign all the return vales to a single
> name.

We do not want the tuple.


Python 2.3.5 (#1, Apr 28 2005, 12:14:04)
[GCC 3.4.3-20050110 (Gentoo Linux 3.4.3.20050110-r2,
ssp-3.4.3.20050110-0, pie-
on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo():
>>> ...     return 1,2,3
>>> ...
>>> (a,b,c)=foo()
>>> print a,b,c
1 2 3
>>>

works.

Of course, you can omit the ():

>>> a,b,c=foo()
>>> print a,b,c
1 2 3

That makes no difference.




Bernd

-- 
Those who desire to give up freedom in order to gain security,
will not have, nor do they deserve, either one. [T. Jefferson]



More information about the Python-list mailing list