Easy questions from a python beginner
sturlamolden
sturlamolden at yahoo.no
Mon Jul 12 10:59:12 EDT 2010
On 12 Jul, 07:51, "Alf P. Steinbach /Usenet" <alf.p.steinbach
+use... at gmail.com> wrote:
> We're talking about defining a 'swap' routine that works on variables.
I did not miss the point. One cannot make a swap function that rebinds
its arguments in the calling stack frame. But a swap function can swap
values, given that the type is not immutable:
def swap(a,b):
a[0],b[0] = b[0],a[0]
>>> a,b = [1],[2]
>>> swap(a,b)
>>> print a,b
[2] [1]
More information about the Python-list
mailing list