checking if a list is empty
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri May 6 22:51:50 EDT 2011
On Fri, 06 May 2011 14:57:21 -0700, scattered wrote:
> is there any problem with
>
> (3) if li == []:
>
> ?
>
> Seems to work when I test it and seems to clearly test what you are
> trying to test. The only problem might be if in some contexts == has the
> semantics of checking for object identity.
Yes, if li == [] works too. But how do you know li is a list and not some
other sequence type?
The advantage of the "if x" test is that it is independent of the type of
x.
--
Steven
More information about the Python-list
mailing list