Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Wed, 18 Nov 2015 22:33:11 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 17 Message-ID: References: NNTP-Posting-Host: 67-130-15-94.dia.static.qwest.net X-Trace: reader1.panix.com 1447885991 1016 67.130.15.94 (18 Nov 2015 22:33:11 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Wed, 18 Nov 2015 22:33:11 +0000 (UTC) User-Agent: slrn/1.0.2 (Linux) Xref: csiph.com comp.lang.python:99004 On 2015-11-18, Ian Kelly wrote: > On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: >> def eList(val, list0=[]): > The list0 parameter has a default value, which is [], an initially > empty list. The default value is evaluated when the function is > defined, not when it is called, so the same list object is used each > time and changes to the list are consequently retained between calls. One might consider this a way to have a local varible inside a function that's "static" a-la C. However, one probably oughtn't. -- Grant Edwards grant.b.edwards Yow! Gibble, Gobble, we at ACCEPT YOU ... gmail.com