Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62613
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <gary.herron@islandtraining.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'advance': 0.07; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'try:': 0.09; 'subject:How': 0.10; 'def': 0.12; 'parentheses': 0.16; 'subject: \n ': 0.16; 'subject:variable': 0.16; 'tuples,': 0.16; 'variables,': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'trying': 0.19; 'basically': 0.19; 'written': 0.21; 'print': 0.22; 'header:User-Agent:1': 0.23; 'necessary.': 0.24; 'received:emailsrvr.com': 0.24; 'received:(smtp server)': 0.26; 'switch': 0.26; 'second': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'gary': 0.31; 'supposed': 0.32; 'subject:from': 0.34; 'but': 0.35; 'subject:one': 0.36; 'vice': 0.36; 'thanks': 0.36; 'question,': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'exchange': 0.63; 'subject:more': 0.64; 'do:': 0.91 |
| X-Virus-Scanned | OK |
| Date | Mon, 23 Dec 2013 01:58:09 -0800 |
| From | Gary Herron <gary.herron@islandtraining.com> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: How can i return more than one value from a function to more than one variable |
| References | <40ddd2cf-483f-423b-9a4d-93f6a5e77df2@googlegroups.com> |
| In-Reply-To | <40ddd2cf-483f-423b-9a4d-93f6a5e77df2@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4545.1387793194.18130.python-list@python.org> (permalink) |
| Lines | 39 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1387793194 news.xs4all.nl 2949 [2001:888:2000:d::a6]:52257 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:62613 |
Show key headers only | View raw
On 12/22/2013 02:54 PM, dec135@msn.com wrote:
> basically what I wanna do is this :
>
> x = 4
> y = 7
> def switch (z,w):
> ***this will switch z to w and vice verca***
> c= z
> z=w
> w=c
> print 'Now x =', w, 'and y = ' , z
> return w
> x = switch(x,y)
>
> 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 ?
>
> thanks in advance
I don't' understand the question, but if you are just trying to exchange
the values of x and y, this will do:
x,y = y,x
If you want a function to return several values to several variables, try:
def fn(...):
# calculate a and b
return a,b
p,q = fn(...)
All these comma-separated sequences are tuples, often written with
parentheses as (x,y)=(y,x) and (p,q)=fn(...), but as here, the
parentheses are often not necessary.
Gary Herron
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
How can i return more than one value from a function to more than one variable dec135@msn.com - 2013-12-22 14:54 -0800 Re: How can i return more than one value from a function to more than one variable Simon Hayward <mail@simonsblog.co.uk> - 2013-12-23 09:36 +0000 Re: How can i return more than one value from a function to more than one variable Rick Johnson <rantingrickjohnson@gmail.com> - 2013-12-22 16:10 -0800 Re: How can i return more than one value from a function to more than one variable Gary Herron <gary.herron@islandtraining.com> - 2013-12-23 01:58 -0800
csiph-web