Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'parameter': 0.05; 'pointer': 0.05; 'received:localnet': 0.07; 'python': 0.08; 'object.': 0.09; 'parameter.': 0.09; 'subject:parameters': 0.09; 'ugly': 0.09; 'def': 0.12; 'wrote:': 0.14; 'from:addr:rohdewald.de': 0.16; 'from:addr:wolfgang': 0.16; 'from:name:wolfgang rohdewald': 0.16; 'local.': 0.16; 'message- id:@rohdewald.de': 0.16; 'received:91.62': 0.16; 'reply- to:addr:rohdewald.de': 0.16; 'reply-to:addr:wolfgang': 0.16; 'subject:function': 0.16; 'wolfgang': 0.16; 'header:In-Reply- To:1': 0.21; 'variable': 0.21; 'seems': 0.21; 'cc:2**0': 0.22; 'once.': 0.23; "doesn't": 0.25; 'function': 0.25; 'object': 0.26; 'pass': 0.27; '(the': 0.28; 'variables': 0.29; 'received:mo-p00-ob.rzone.de': 0.30; 'it.': 0.31; 'to:addr:python- list': 0.33; 'list': 0.33; 'actually': 0.33; 'list.': 0.33; 'there': 0.35; 'header:User-Agent:1': 0.35; 'function.': 0.35; 'reference': 0.35; 'considered': 0.36; 'hold': 0.36; 'charset:us- ascii': 0.36; 'references': 0.37; 'think': 0.38; 'could': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'called': 0.39; 'unless': 0.39; 'itself.': 0.39; 'either': 0.39; 'to:addr:python.org': 0.39; 'more': 0.60; 'within': 0.60; 'header:Message-Id:1': 0.62; 'header :Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1306662444; l=949; s=domk; d=rohdewald.de; h=Content-Transfer-Encoding:Content-Type:MIME-Version:In-Reply-To: References:Cc:Date:Subject:To:Reply-To:From:X-RZG-CLASS-ID:X-RZG-AUTH; bh=YHbHzW6rEi2X3DTl2JoPyZ5e2xo=; b=rt/F+z2c/hyuHWvcssps/DY4oIw+QWf5X06Cz6MEwW4x/ldzr8t+OFbzBpZdY8OFySZ Z00KT6RFFBOJ+zlmdtLvf1MTB8BF9ceH/qN5eeLj/pi7BAnVsvOJ/meXfrtYMigcsa/5r fAfPu2nIipIoKHD7oxrCMak+mJirJ7HPr+w= X-RZG-AUTH: :O2MIc0epdfgAjoV+frHI3UhxNCLBO5P+YS73lHhJYRD2uAuzaM+5N8MTpurqLXil X-RZG-CLASS-ID: mo00 From: Wolfgang Rohdewald To: python-list@python.org Subject: Re: scope of function parameters Date: Sun, 29 May 2011 11:47:26 +0200 User-Agent: KMail/1.13.6 (Linux/2.6.38-8-generic; KDE/4.6.3; x86_64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: wolfgang@rohdewald.de List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306662671 news.xs4all.nl 49178 [::ffff:82.94.164.166]:38804 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6522 On Sonntag 29 Mai 2011, Henry Olders wrote: > It seems that in Python, a variable inside a function is > global unless it's assigned. no, they are local > I would have thought that a function parameter would > automatically be considered local to the function. It doesn't > make sense to me to pass a global to a function as a > parameter. it is local. But consider what you actually passed: You did not pass a copy of the list but the list itself. You could also say you passed a reference to the list. All python variables only hold a pointer (the id) to an object. This object has a reference count and is automatically deleted when there are no more references to it. If you want a local copy of the list you can either do what you called being ugly or do just that within the function itself - which I think is cleaner and only required once. def fnc2(c): c = c[:] c[1] = 'having' return c -- Wolfgang