Entry
Mutable function arguments (was: Interesting thread...)
Jul 5th, 2000 10:02
Nathan Wallace, Hans Nowak, Snippet 224, ze5yr
"""
Packages: basic_datatypes.lists
"""
"""
In article <Pine.GSO.4.10.9908131047510.3761-100000@crusoe.crusoe.net>,
japhy@pobox.com wrote:
> I wish I could change a string in-place with a function.*
> [bobbit]
> * meaning:
>
> def func(str):
> # something modifying str
>
> str = "foo"
> func(str)
> print str # prints... "bar", for example
Enclose it in a list, which is mutable:
"""
def func(l):
l[0]="bar"
l=["foo"]
func(l)
print l
# ['bar']