One another simple method is to check its count using the *len *method. eg:
if len(mylist) == 0: print "empty list" This is particularly useful in situations where checking emptiness alone is not enough. On Mon, Jun 9, 2008 at 8:24 PM, W W <[EMAIL PROTECTED]> wrote: > >>> def empty_or_not(mylist): > ... if mylist: > ... print "Not empty" > ... elif not mylist: > ... print "Empty!" > ... > >>> empty_or_not([]) > Empty! > >>> foo = [] > >>> empty_or_not(foo) > Empty! > >>> foo.append('hi') > >>> empty_or_not(foo) > Not empty > > My guess is that if any object is empty, it's considered "not". > > HTH, > Wayne > > > On Mon, Jun 9, 2008 at 9:25 AM, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> wrote: > > Hello > > Sorry if this is a basic question, but how do I check if list is empty > > or not and return True or False ;) > > Thanks > > David > > > > > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > > > -- > To be considered stupid and to be told so is more painful than being > called gluttonous, mendacious, violent, lascivious, lazy, cowardly: > every weakness, every vice, has found its defenders, its rhetoric, its > ennoblement and exaltation, but stupidity hasn't. - Primo Levi > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- C S Shyam Sundar [mobile] +91-97877-SHYAM | [voip] +1-425-998-1134 "It's easy to tell the difference between right and wrong. What's hard is choosing the wrong that's more right."
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor