None in string formatting

Scott David Daniels Scott.Daniels at Acm.Org
Tue Mar 8 16:03:18 EST 2005


Jorge Godoy wrote:
> rodney.maxwell at gmail.com writes:
>>Was doing some string formatting, noticed the following:
>>>>>x = None
>>>>>"%s" % x
>>'None'
>>
>>Is there a reason it maps to 'None'? I had expected ''.
> 
> How would know, then, if there was no value at all or if it was an empty
> string? 
> 

If you want the other effect, you can always do:

     "%s" % (x or '')

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list