How to check if a string is empty in python?

Basilisk96 basilisk96 at gmail.com
Wed May 2 17:02:29 EDT 2007


> How do you know that s is a string?

It's a presumption based on the original problem statement.

The example shown is a simple T/F check, which happens to determine
the "emptiness" of strings.
If type checking is absolutely necessary, one could use

if isinstance(s, basestring):
    if s:
        print "not empty"
    else:
        print "empty"





More information about the Python-list mailing list