What way is the best to check an empty list?

Andre Engels andreengels at gmail.com
Wed Mar 25 15:49:14 CET 2009

On Wed, Mar 25, 2009 at 3:38 PM, srinivasan srinivas
<sri_annauni at yahoo.co.in> wrote:
> For ex: to check list 'A' is empty or not..
> if A == []:
> if A.count == 0:
> if len(A) == 0:
> if not A:

I would go for the last one, because it has the highest likelihood of
doing what is intended when fed with something that is 'list-like'
rather than a list. The second one is incorrect, by the way. A.count
is something completely different.

André Engels, andreengels at gmail.com

More information about the Python-list mailing list