Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Thu, 19 Nov 2015 12:26:28 +1100 Lines: 30 Message-ID: References: <03515f27-fb4c-49f0-9f02-2f5b5a8d16e5@googlegroups.com> <564D1F93.7000902@mrabarnett.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de B97rAvCiypPJt4qaUXh+1gsIAxJlPYDcEKqqAVmnuVQw== Cancel-Lock: sha1:vd/esA9OV7JJinUsub02+G5/OcE= 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; 'value,': 0.03; 'mrab': 0.05; 'defined,': 0.09; 'deletes': 0.09; 'deletion': 0.09; 'dict': 0.09; 'effect.': 0.09; 'parameter.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'references,': 0.09; 'python': 0.10; '*never*': 0.16; 'greatness': 0.16; 'measured': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'exists': 0.18; 'machine': 0.21; 'affects': 0.22; 'exists.': 0.22; 'parameter': 0.22; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'header:X-Complaints-To:1': 0.26; 'point.': 0.27; 'thorough': 0.27; 'function': 0.28; 'list': 0.34; 'so,': 0.35; 'behind': 0.35; 'set.': 0.35; 'list,': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'no,': 0.38; 'delete': 0.38; 'names': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'future': 0.60; 'collection': 0.60; 'default': 0.61; 'wall': 0.63; 'more': 0.63; '_o__)': 0.84; 'liberty': 0.84; 'received:125': 0.84; 'scenes': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99023 MRAB writes: > On 2015-11-19 00:34, fl wrote: > > What does 'del' do? It does not look like a thorough list deletion > > from the effect. > > No, "del list1" doesn't delete the list, it deletes the name "list1". > The list still exists as the default parameter. More generally, ‘del’ deletes a *reference*. Names are one kind of reference; others include items in a collection such as a dict or set. Deleting a reference *never* affects the value referred to. However, once a value has no more references, the program can no longer access it, so the Python machine is at liberty to delete the value behind the scenes at some future point. > A default parameter is evaluated when the function is defined, and > that value exists as the default as long as the function exists. So, because the function retains a reference to the value, the value remains unaffected when you delete the reference ‘list1’. -- \ “True greatness is measured by how much freedom you give to | `\ others, not by how much you can coerce others to do what you | _o__) want.” —Larry Wall | Ben Finney