Re: Formatted Integer With Specified Number Of Digits

2025-10-26 Thread Michael Torrie via Python-list
On 10/24/25 4:38 AM, Alan Bawden wrote: > Paul Rubin writes: > >Lawrence D’Oliveiro writes: >> >>> "%#0.3x" % 2 >> '0x002' > >f'0x{2:03x} > > Won't work for negative numbers. That's true. For negative numbers the padding would have to be Fs instead of 0s. -- https:/

Re: Formatted Integer With Specified Number Of Digits

2025-10-24 Thread Alan Bawden
Paul Rubin writes: Lawrence D’Oliveiro writes: > >>> "%#0.3x" % 2 > '0x002' f'0x{2:03x} Won't work for negative numbers. -- Alan Bawden -- https://mail.python.org/mailman3//lists/python-list.python.org

Re: Formatted Integer With Specified Number Of Digits

2025-10-19 Thread songbird
Lawrence D’Oliveiro wrote: > Formatting an integer with 3 digits, excluding base specifier: > > >>> "%#0.3x" % 2 > '0x002' > > No equivalent to this in any of the other ways that Python allows for > formatting: > > >>> format(2, "#03x") > '0x2' > > (Not what I want) > > >>>