Re: Formatted Integer With Specified Number Of Digits

Gilmeh Serda <[email protected]> Sun, 19 Oct 2025 09:17:04 GMT
Newsgroups comp.lang.python
Organization Easynews - www.easynews.com
Message-ID <[email protected]>
On Sun, 19 Oct 2025 07:26:44 -0000 (UTC), Lawrence D’Oliveiro wrote:

> Why not?

I have no idea

you could try zfill:

>>> f"magic number: {'42'.zfill(4)}"
'magic number: 0042'

>>> f"magic number: {str(42).zfill(4)}"
'magic number: 0042'

more info:
https://fstring.help/cheat/

-- 
Gilmeh

Necessity is a mother.