None in string formatting
Steven Bethard
steven.bethard at gmail.com
Tue Mar 8 14:58:12 EST 2005
rodney.maxwell at gmail.com wrote:
> Was doing some string formatting, noticed the following:
>
>>>>x = None
>>>>"%s" % x
>
> 'None'
>
> Is there a reason it maps to 'None'? I had expected ''.
Can you explain why you expected that? A few other examples that make
me not expect what you do:
py> '%s' % False
'False'
py> '%s' % []
'[]'
py> '%s' % {}
'{}'
py> '%s' % set()
'set([])'
All of the objects above evaluate to False in a boolean context like ''
does, but they display a string appropriate to their type. Since None
has it's own type (NoneType), I would expect similar behavior.
STeVe
More information about the Python-list
mailing list