Dick Moores wrote:

> I've also seen things like this:
>  >>> a = []
>  >>> if not a:
> ...     print 'a is empty'
> ...
> a is empty
>  >>>
> 
> Isn't this preferable?:
>  >>> a = []
>  >>> if a == []:
> ...     print 'a is empty'
> ...
> a is empty

I like the simplicity and consistency of
   if a
or
   if not a

which will test for empty if a is a list, dict, string or set.

Of course strictly speaking
   if a
and
   if a == []
are not equivalent unless you can guarantee that a references a list 
(not None or any other kind of object) but for many purposes they are.

Kent
Kent
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to