How can i compare a string which is non null and empty
Shane Geiger
sgeiger at ncee.net
Sun Apr 1 22:52:23 EDT 2007
It is probably worth noting that the example is not executable code:
str() is a function.
sgeiger3 at nycsr0002:~$ python
Python 2.4.4c0 (#2, Jul 30 2006, 15:43:58)
[GCC 4.1.2 20060715 (prerelease) (Debian 4.1.1-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> if str: print "whoah, str is a function!"
...
whoah, str is a function!
>>>
/me pines for the day when all examples are executable code
Grant Edwards wrote:
> 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>
>
>
>
--
Shane Geiger
IT Director
National Council on Economic Education
sgeiger at ncee.net | 402-438-8958 | http://www.ncee.net
Leading the Campaign for Economic and Financial Literacy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sgeiger.vcf
Type: text/x-vcard
Size: 310 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20070401/8a388b21/attachment.vcf>
More information about the Python-list
mailing list