A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/081485.html below:

Newbie Q: var params

Newbie Q: var paramszzzzz zzizz_ at notmail.com
Tue Apr 10 23:46:11 EDT 2001
Hi all,

I (possibly incorrectly) thought that parameters passed in functions
were modifiable by default in Python, here is some code that I tested
with:
>>> x=[1,2,3]
>>> def paramtest(parameter):
... 	print "parameter =",parameter
... 	print "parameter ID =",id(parameter)
... 	parameter.append("hello")
... 	print "new parameter =",parameter
... 	print "new parameter ID =",id(parameter)
... 	parameter=[2,4,6,8]
... 	print "modified parameter =",parameter
... 	print "modified parameter ID =",id(parameter)
... 	
>>> paramtest(x)
parameter = [1, 2, 3]
parameter ID = 20270396
new parameter = [1, 2, 3, 'hello']
new parameter ID = 20270396
modified parameter = [2, 4, 6, 8]
modified parameter ID = 20263708
>>> x
[1, 2, 3, 'hello']

It looks like "parameter=[2,4,6,8]" creates a new local variable that
overrides the passed parameter. How do I do this properly so that the
passed parameter changes in all parameter type cases?

Thanks,

z.

Regards,

zzzzz.
---------------------

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4