Sujet : Re: Formatting a str as a number
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 27. Aug 2024, 22:36:47
Autres entêtes
Organisation : Stefan Ram
Message-ID : <doc-20240827223515@ram.dialup.fu-berlin.de>
References : 1 2 3 4
Gilmeh Serda <
gilmeh.serda@nothing.here.invalid> wrote or quoted:
On 25 Aug 2024 15:46:25 GMT, Stefan Ram wrote:
f"{int(number):>20,}"
Great. Thanks. Do you have a link to where that's documented?
I did web search, found nothing.
Stoked to hear you're into it!
For docs, I usually snag the PDFs from "python.org," especially
"reference.pdf" (the Python Language Reference) and "library.pdf"
(the Python Library Reference), then I search them for keywords.
The f-string stuff is laid out in "The Python Language Reference"
since they're part of the language itself. A quick search for
"f-str" gets you to "2.4.3 Formatted string literals," which says,
"The result is then formatted using the format() protocol." So, you
got to check out "The Python Library Reference" too! Searching for
"format(" there zooms you right to "6.1.3 Format String Syntax"
(via "Format Specification Mini-Language").
But honestly, I usually just hit up a chatbot first. I'll drop
in my code and say, "How can I make this shorter?".