Empty string is False right?

AJ Ostergaard aj at cubbyhole.net
Sat Jan 31 07:16:19 EST 2009


Hi Ralf,

Thanks for that but why:

 >>> '' and True
''

Surely that should be False?!?

Regards,
AJ


On 31 Jan 2009, at 12:12, Ralf Schoenian wrote:

> AJ Ostergaard wrote:
>> Hello,
>> First post so bear with me if I'm being a numpty ...
>> Is it me or is there something slightly counter intuitive and thus  
>> not so pythonesque about this:
>> >>> s = ''
>> >>> if s: True
>> .... else: False
>> ....
>> False
>> >>> s and eval(s)
>> ''
>> >>>
>> Regards,
>> AJ
>
> Hi,
>
> yes, the following evaluates to False:
> empty String: ''
> empty list: []
> empty tuple: ()
> empty dict: {}
> 0, None
> and False of course
>
> Regards,
> Ralf




More information about the Python-list mailing list