Empty string is False right?

Ben Finney bignose+hates-spam at benfinney.id.au
Sat Jan 31 07:56:43 EST 2009


Ralf Schoenian <ralf at schoenian-online.de> writes:

> yes, the following evaluates to False:
> empty String: ''
> empty list: []
> empty tuple: ()
> empty dict: {}
> 0, None
> and False of course

More precisely: All the above evaluate as Boolean false. But only one
of them evaluates to False: the object bound to the name ‘False’.

    >>> bool(None) == bool(False)
    True
    >>> None == False
    False
    >>> None is False
    False

    >>> bool('') == bool(False)
    True
    >>> '' == False
    False
    >>> '' is False
    False

    >>> bool(0) == bool(False)
    True
    >>> 0 == False
    False
    >>> 0 is False
    False

-- 
 \         “What is it that makes a complete stranger dive into an icy |
  `\   river to save a solid gold baby? Maybe we'll never know.” —Jack |
_o__)                                                           Handey |
Ben Finney



More information about the Python-list mailing list