Empty string is False right?

Diez B. Roggisch deets at nospam.web.de
Sat Jan 31 11:09:37 EST 2009


AJ Ostergaard schrieb:
> Hi Ralf,
> 
> Thanks for that but why:
> 
>  >>> '' and True
> ''
> 
> Surely that should be False?!?

No. Please read the section in the language reference about the and/or 
operators.

"and" will return the first false value, or the right side. Thus

'' and True -> ''

True and '' -> ''

'a' and True -> True

True and 'a' -> 'a'

"or" does the same, obviously with the or-semantics:


'' or False -> False
False or '' -> ''
'' or True -> True
True or '' -> True
'a' or False -> 'a'
False or 'a' -> 'a'

Diez




More information about the Python-list mailing list