Mutable default values for function parameters

Steve Holden sholden at holdenweb.com
Thu Oct 4 23:47:03 EDT 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 [[]])[0]
> >
> > Here is the test:
> >
> > def test(d = None):
> >     return ((d is not None and [d]) or [[]])[0]
> >
> > 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 mailing list