Re: Formatted Integer With Specified Number Of Digits

Gilmeh Serda <[email protected]>
Newsgroups gmane.comp.python.general
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.
-- 
https://mail.python.org/mailman3//lists/python-list.python.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.