Bug in format specification in Python 3?

greg greg at cosc.canterbury.ac.nz
Wed Aug 12 08:06:13 CEST 2009

Robert Dailey wrote:

> 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?

Yes, it's the total field width. This is consistent with
the other formats, in which it includes decimal points,
signs, etc.

If you don't want that, then write the format string as

   'This is a hex number: 0x{:08x}'


More information about the Python-list mailing list