What is a function parameter =[] for?
John Gordon
gordon at panix.com
Wed Nov 18 17:05:19 EST 2015
In <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862 at googlegroups.com> fl <rxjwg98 at gmail.com> writes:
> 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')
That is a default parameter. If eList() is called without an argument for
list0, it will use [] as the default value.
--
John Gordon A is for Amy, who fell down the stairs
gordon at panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
More information about the Python-list
mailing list