Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6585
| From | Christopher Head <chead@is.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: scope of function parameters |
| Date | 2011-05-29 14:48 -0700 |
| Organization | solani.org |
| Message-ID | <20110529144853.2adff584@kruskal.chead> (permalink) |
| References | <F8395F78-615E-4FBD-B6FC-1D6173EAEA45@mcgill.ca> <201105291147.26545.wolfgang@rohdewald.de> <mailman.2237.1306700356.9059.python-list@python.org> |
On Sun, 29 May 2011 16:19:11 -0400 Henry Olders <henry.olders@mcgill.ca> wrote: > > def fnc2(c): > > c = c[:] > > c[1] = 'having' > > return c > > Thank you, Wolfgang. That certainly works, but to me it is still a > workaround to deal with the consequence of a particular decision. > From my perspective, a function parameter should be considered as > having been assigned (although the exact assignment will not be known > until runtime), and as an assigned variable, it should be considered > local. > > Henry This has nothing to do with function parameters and everything to do with what a "variable name" actually means. You can get the same effect with only globals: >>> x=[1,2,3] >>> y=x >>> x.append(7) >>> y [1, 2, 3, 7] Why in the world does "y" end with 7, even though it was appended to "x"? Simple: because "x" and "y" are two names for the same list, as Henry explained. No functions involved, no locals, no parameters, no scoping. Again, if "y=x" were instead "y=x[:]" then the output would be "[1,2,3]" because "y" would refer to a copy of the list rather than the same list. Chris
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: scope of function parameters Henry Olders <henry.olders@mcgill.ca> - 2011-05-29 16:19 -0400 Re: scope of function parameters Christopher Head <chead@is.invalid> - 2011-05-29 14:48 -0700
csiph-web