Is there a better way? [combining f-string, thousands separator, right align]

Pierre Fortin pf at pfortin.com
Sun Aug 25 21:38:22 EDT 2024


On Sun, 25 Aug 2024 15:12:20 GMT Gilmeh Serda via Python-list wrote:

>Subject explains it, or ask.
>
>This is a bloody mess:
>
>>>> s = "123456789" # arrives as str
>>>> f"{f'{int(s):,}': >20}"  
>'         123,456,789'
>
Oops.. forgot comma

f"{int(s):>20,}"


More information about the Python-list mailing list