Mutable default values for function parameters
sholden at holdenweb.com
Fri Oct 5 05:47:03 CEST 2001
"Ignacio Vazquez-Abrams" <ignacio at openservices.net> wrote in message
news:mailman.1002232865.30569.python-list at python.org...
> On Thu, 4 Oct 2001, Brian Quinlan wrote:
> > Here is my proposed expression:
> > d = ((d is not None and [d]) or [])
> > Here is the test:
> > def test(d = None):
> > return ((d is not None and [d]) or [])
> > assert test() == 
> > assert test(None) == 
> > assert test(0) == 0
> > assert test('') == ''
> > assert test(5) == 5
> > assert test([1,2,3]) == [1,2,3]
> > I believe that those are the semantics that you are looking for? And
> > so easy to understand...
> This is your brain on drugs. Any questions? ;)
Yes. Why isn't he sharing them round?
don't-bogart-that-joint-ly y'rs - steve
More information about the Python-list