How to check if a string is empty in python?

mensanator at aol.com mensanator at aol.com
Thu May 3 16:30:37 EDT 2007


On May 3, 2:03 pm, John Salerno <johnj... at NOSPAMgmail.com> wrote:
> mensana... at aol.com wrote:
> > On May 2, 3:49 pm, Basilisk96 <basilis... at gmail.com> wrote:
> >> A simple
>
> >> if s:
> >>     print "not empty"
> >> else:
> >>     print "empty"
>
> >> will do.
>
> > How do you know that s is a string?
>
> Seems like a fair assumption given the OP's question and example.

A fair assumption for languages other than Python.

Just because s was a string at some point in the past
doesn't mean it's a string now.




More information about the Python-list mailing list