Scope troubles with a swap function
Duncan Booth
duncan at NOSPAMrcp.co.uk
Fri Aug 10 12:24:53 EDT 2001
"Matthew D. Wood" <woodm at equire.com> wrote in
news:mailman.997452856.7709.python-list at python.org:
> How do you make a swap function?
>
The easy way:
a, b = b, a
and of course you aren't restricted to two values:
a, b, c = b, c, a
If you are *really* sure you want a function that swaps its arguments, try:
def swap(a, b): return b, a
a, b = swap(a, b)
Python isn't C. Its better.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list