Re: How can i return more than one value from a function to more than one variable
Dave Angel
davea at davea.name
Sun Dec 22 19:57:56 EST 2013
On Sun, 22 Dec 2013 15:41:06 -0800 (PST), Bob Rashkin
<rrashkin at gmail.com> wrote:
> On Sunday, December 22, 2013 4:54:46 PM UTC-6, dec... at msn.com wrote:
> > How am I supposed to do so I can return also a value to the
variable y WITHOUT printing 'Now x =', w, 'and y = ' , z a second
time ?
You are apparently asking 3 questions.
To exchange 2 values, use the tuple-unpack approach.
a, b = b, a
To get the equivalent of multiple return values, return a tuple.
def myfunc (a):
x = a*a
y = 2+a
return x, y
p , q = myfunc (5)
To avoid executing your print twice, call the function only once.
And a bonus one: to avoid my getting a blank message in this text
newsgroup, post in text, not html.
--
DaveA
More information about the Python-list
mailing list