why are these not the same?

Fredrik Lundh fredrik at pythonware.com
Thu Jan 20 04:38:56 EST 2005


Lowell Kirsh wrote:
> On a webpage (see link below) I read that the following 2 forms are not the same and that the 
> second should be avoided. They look the same to me. What's the difference?

> def functionF(argString="abc", argList = None):
>         if argList is None: argList = []
>         ...
>
> def functionF(argString="abc", argList=None):
>         argList = argList or []
>         ...

"is None" tests for None, "argList or" tests for a false value.  None is
false, but many non-None objects are also false.

"should be avoided" sounds like overly zealous advice to me; use the
latter form if you understand it.

</F> 






More information about the Python-list mailing list