True/False formats as 1/0 in a fixed width string

Frank Millman frank at chagford.com
Wed Mar 27 10:14:00 CET 2013


On 27/03/2013 10:52, Peter Otten wrote:
> Frank Millman wrote:
>
>>   >>> '{}'.format(True)
>> 'True'
>>   >>> '{:<10}'.format(True)
>> '1'
>>
>> One might want to format True/False in a fixed width string, but it
>> returns 1/0 instead. Is there any way to make this work?
>
>>>> "{!s:<10}".format(True)
> 'True'
>
>

Works perfectly.

Thanks, Peter

Frank





More information about the Python-list mailing list