How can i return more than one value from a function to more than one variable

Rick Johnson rantingrickjohnson at
Mon Dec 23 01:10:56 CET 2013

On Sunday, December 22, 2013 4:54:46 PM UTC-6, dec... at 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)

If your intent is to swap the values of two variables (which
is really rebinding the names only) then why do you need a
function at all when you could explicitly swap the values
yourself? What gain would a function give you -- even if you
could do it?

More information about the Python-list mailing list