How can i compare a string which is non null and empty

Grant Edwards grante at visi.com
Sun Apr 1 22:17:46 EDT 2007


On 2007-04-01, Plissken.s at gmail.com <Plissken.s at gmail.com> wrote:

> how can i compare a string which is non null and empty?
[...]
> In java,I do this:
> if (str != null) && (!str.equals("")) ....
>
> how can i do that in python?

If you want to litterally do that, it's

  if (str != None) and (str != ""):
    <whatever>  

However, the standard idiom for doing that in Python is

  if str:
    <whatever>


-- 
Grant Edwards                   grante             Yow!  I'm RELIGIOUS!! I
                                  at               love a man with a
                               visi.com            HAIRPIECE!! Equip me with
                                                   MISSILES!!



More information about the Python-list mailing list