How to check if a string is empty in python?
Tim Williams
listserver at tdw.net
Fri May 4 07:06:04 EDT 2007
On 4 May 2007 03:02:37 -0700, Jaswant <mailme.gurpreet at gmail.com> wrote:
> This is a simple way to do it i think
>
>
> s=hello
>
> >>> if(len(s)==0):
> .... print "Empty"
> .... else:
> .... print s
> ....
> hello
Not as simple as " If not s: "
and nowhere near as simple as " print s or 'Empty' " :) :)
>>> s = ''
>>> print s or 'Empty'
Empty
>>> s = 'hello'
>>> print s or 'Empty'
hello
>>>
More information about the Python-list
mailing list