>>> 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