Bug in format specification in Python 3?

AggieDan04 danb_83 at yahoo.com
Wed Aug 12 02:08:01 CEST 2009

On Aug 11, 3:28 pm, Robert Dailey <rcdai... at gmail.com> wrote:
> Hello,
> According to the Python 3.1 documentation, I can have a format
> specification like so:
> print( 'This is a hex number: {:#08x}'.format( 4 ) )
> This will print:
> This is a hex number: 0x000004
> I notice that the '0x' portion is counted in the width, which was
> specified as 8. This seems wrong to me. Is this by design? If so, why?
> I expect that the width portion to only apply to the input + padding
> only. I don't consider the '0x' portion part of the padding. But maybe
> it is...

It's unintuitive to me, too, but it's the same thing that Python 2.x

>>> print '%#08x' % 4

More information about the Python-list mailing list