How to check if a string is empty in python?

John Machin sjmachin at lexicon.net
Wed May 2 18:58:44 EDT 2007


On May 3, 8:50 am, Steven D'Aprano
<s... at REMOVE.THIS.cybersource.com.au> wrote:
> On Wed, 02 May 2007 13:35:47 -0700, noagbodjivictor wrote:
> > How to check if a string is empty in python?
> > if(s == "") ??
>
> In no particular order, all of these methods will work:
>
[snip]
>
> # test that s has none of any character
> if not filter(None, [1 + s.find(chr(n)) for n in range(256)]):
>
> That last one is really only good for wasting CPU cycles.

Have you considered
    if not re.match(".+$", s):
?





More information about the Python-list mailing list