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

Liste des GroupesRevenir à cl python 
Sujet : Re: Is there a better way? [combining f-string, thousands separator, right align]
De : python (at) *nospam* mrabarnett.plus.com (MRAB)
Groupes : comp.lang.python
Date : 26. Aug 2024, 03:55:03
Autres entêtes
Message-ID : <mailman.3.1724637492.2917.python-list@python.org>
References : 1 2
User-Agent : Mozilla Thunderbird
On 2024-08-25 16:12, 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'
 
You don't need to format twice; you can combine them:
 >>> s = "123456789"
 >>> f'{int(s): >20,}'
'         123,456,789'
or if you rely on default behaviour:
 >>> f'{int(s):20,}'
'         123,456,789'

Date Sujet#  Auteur
26 Aug 24 o Re: Is there a better way? [combining f-string, thousands separator, right align]1MRAB

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal