Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'assign': 0.07; 'advance': 0.07; 'function,': 0.09; 'received:internal': 0.09; 'subject:How': 0.10; 'def': 0.12; 'assignment.': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'subject: \n ': 0.16; 'subject:variable': 0.16; 'tuple': 0.16; 'y):': 0.16; 'variable': 0.18; 'basically': 0.19; 'print': 0.22; 'switch': 0.26; 'second': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'supposed': 0.32; 'subject:from': 0.34; 'received:66': 0.35; 'subject:one': 0.36; 'vice': 0.36; 'thanks': 0.36; 'received:10': 0.37; 'to:addr:python-list': 0.38; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'header:Message-Id:1': 0.63; 'subject:more': 0.64; 'from:addr:mail': 0.83 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=simonsblog.co.uk; h=message-id:from:to:mime-version:content-transfer-encoding :content-type:in-reply-to:references:subject:date; s=mesmtp; bh= UenS7B9clh4yBFhk+02c55dLmG0=; b=LVqtsqXqKAgc8OjRX01q0GgCm8HDoL9l 9KNDmPEwfJrLyxSifwAUTyMKLS6nQi3wd/oerc30iMUPFehZkSMqteqz5d4TDflq 7a3q78Lq4antdSdpXMsePoBx4X52EIrtzgYOZCFW12HRD9/rMDV7FCZO9I4V9G/f K8TtYmE9mOs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=smtpout; bh=UenS7B9clh4yBFhk+02c55dLmG0=; b=gj9 +wtTwZHFEtyLYn65vFXuEfkN1bTXgmtp97lsbBzjiji6VGOvxCEfOTgy67R3ruAv MM4OZn88QlgabOD368zxN1Oy/mcuw5QoIWxMr7yTjVMzuiAr4Gpzn52RWu1YAdfV opVzA4W7VZpKJM37VmTbCkvxQDkjOBCUI9JzN5qI= X-Sasl-Enc: iICbwQ8ip/SY1Ai+aXs1U+RyYp9RgM9vlCYXOwVBAjwM 1387791416 From: Simon Hayward To: python-list@python.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Mailer: MessagingEngine.com Webmail Interface - ajax-2b496f6a In-Reply-To: <40ddd2cf-483f-423b-9a4d-93f6a5e77df2@googlegroups.com> References: <40ddd2cf-483f-423b-9a4d-93f6a5e77df2@googlegroups.com> Subject: Re: How can i return more than one value from a function to more than one variable Date: Mon, 23 Dec 2013 09:36:56 +0000 X-Mailman-Approved-At: Mon, 23 Dec 2013 10:52:17 +0100 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387792338 news.xs4all.nl 2936 [2001:888:2000:d::a6]:38257 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62609 > 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 Using multiple assignment. # Swap values x, y = 4, 7 y, x = x, y Or to keep this in a function, return a tuple and assign from that: def switch(x, y): return y, x x, y = switch(x, y)