Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62568
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re: How can i return more than one value from a function to more than one variable |
| Date | 2013-12-22 19:57 -0500 |
| References | <40ddd2cf-483f-423b-9a4d-93f6a5e77df2@googlegroups.com> <8e01f218-ec00-4d01-ab82-53e1ea7670e2@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4518.1387760206.18130.python-list@python.org> (permalink) |
On Sun, 22 Dec 2013 15:41:06 -0800 (PST), Bob Rashkin
<rrashkin@gmail.com> wrote:
> On Sunday, December 22, 2013 4:54:46 PM UTC-6, dec...@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: How can i return more than one value from a function to more than one variable Bob Rashkin <rrashkin@gmail.com> - 2013-12-22 15:41 -0800
Re: How can i return more than one value from a function to more than one variable Joel Goldstick <joel.goldstick@gmail.com> - 2013-12-22 19:05 -0500
Re: How can i return more than one value from a function to more than one variable Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-23 00:37 +0000
Re: How can i return more than one value from a function to more than one variable Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-22 22:17 -0500
Re: How can i return more than one value from a function to more than
one variable Dave Angel <davea@davea.name> - 2013-12-22 19:57 -0500
Re: How can i return more than one value from a function to more than one variable Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-23 11:45 +1100
csiph-web