[Tutor] pointers for python?
Gabor Borgulya
bvg.pythontutor at freemail.hu
Mon Oct 6 20:37:12 EDT 2003
> > >def inc(x):
> > > x+=1
> > >
> > >a=1
> > >inc(a)
> > >print a
> > >
> > >prints "1"
> > >
> > >is there a way to get the inc() function to modify the original
> > >variable, even though it's not in the function's scope?
In this solution a and x are lists, which are mutable types. You could
choose any mutable types.
def inc(x):
x[0]+=1
a=[1]
inc(a)
print a[0]
Gábor
More information about the Tutor
mailing list