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

Grant Edwards grante at visi.com
Mon Apr 2 04:56:49 CEST 2007


On 2007-04-02, Shane Geiger <sgeiger at ncee.net> 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>
>
> It is probably worth noting that the example is not executable code:  
> str() is a function.

Yea, sorry about that.

-- 
Grant Edwards                   grante             Yow!  Now I'm concentrating
                                  at               on a specific tank battle
                               visi.com            toward the end of World
                                                   War II!



More information about the Python-list mailing list