Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: What is a function parameter =[] for? Date: Wed, 18 Nov 2015 15:11:43 -0700 Lines: 21 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de ati8FW0LUBZOPoY/n4W/sgok64WFV4XZLLGsQmrfbLmw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'value,': 0.03; '[],': 0.07; 'calls.': 0.07; 'defined,': 0.09; 'retained': 0.09; 'def': 0.13; 'wed,': 0.15; 'called,': 0.16; 'effect,': 0.16; 'list1': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'changes': 0.20; '2015': 0.20; 'parameter': 0.22; 'thanks,': 0.24; 'second': 0.24; 'tried': 0.24; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'initially': 0.30; 'me?': 0.34; 'previous': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'nov': 0.35; 'something': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'setting': 0.37; 'received:209.85.213': 0.37; 'list.': 0.37; 'received:209': 0.38; 'hi,': 0.38; 'to:addr:python.org': 0.40; 'default': 0.61; 'between': 0.65; 'consequently': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=62+aOgmW3rGa4VsHnurfZAOKTVheCTNj1CNR+7SS4EI=; b=lHR+mZuBxRSTJ0AzJy6/FMT215nH0zViYrzWjtIx/gftuEx7Kwlz8vjxmavHZdDcZo xFiAGxcbzb+RWs5+dRLx64RBkI4n0inA3IdfzAN1qaqAVSOlTnanu8iO+a5UJ57XoxLm ccwisCoP/2cMCyPDZ+iZayx6/H2N7mRciss67x5+QNY/JIRBGh8/ajndiNybiYMdTzZI PRoUruIu5Or94baoqQkyfRaQDhd18Q3IYLzaAZ4UQRVOCd4eOGiJxOXmz4oK0CP/ZFiJ Id+ZfFgb09uHD44yIvfN9XkYf2Kl8ekcUVKYQfYZcMNlOvkmXruohIHVn1Ys2QdPPLpp nArQ== X-Received: by 10.50.43.129 with SMTP id w1mr5570136igl.93.1447884742795; Wed, 18 Nov 2015 14:12:22 -0800 (PST) In-Reply-To: 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:99003 On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: > Hi, > > I have tried the below function and find that it can remember the previous > setting value to 'val'. I think the second parameter has something on this > effect, but I don't know the name and function of '=[]' in this application. > > Could you explain a little to me? > Thanks, > > > def eList(val, list0=[]): > list0.append(val) > return list0 > list1 = eList(12) > list1 = eList('a') 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.