“Texte de format Python” Réponses codées

Texte de format Python

# Make sure to run in the right terminal

red = '\033[91m'
green = '\033[92m'
blue = '\033[94m'
bold = '\033[1m'
italics = '\033[3m'
underline = '\033[4m'
end = '\033[0m'

print (red + underline + 'Test!... Test!' + end)
Jittery Jaguar

chaînes de formatage python

Number		Format		Output   					Description
3.1415926	{:.2f}		3.14			Format float 2 decimal places
3.1415926	{:+.2f}		+3.14			Format float 2 decimal places with sign
-1	{:+.2f}				-1.00					Format float 2 decimal places with sign
2.71828	{:.0f}			3					Format float with no decimal places
5	{:0>2d}				05						Pad number with zeros (left padding, width 2)
5	{:x<4d}				5xxx					Pad number with x’s (right padding, width 4)
10	{:x<4d}				10xx					Pad number with x’s (right padding, width 4)
1000000	{:,}			1,000,000	      Number format with comma separator
0.25	{:.2%}		    25.00%	         Format percentage
1000000000	{:.2e}		1.00e+09		Exponent notation
13	{:10d}	      	    13				Right aligned (default, width 10)
13	{:<10d}				13						Left aligned (width 10)
13	{:^10d}	    		13					Center aligned (width 10)
armin

Réponses similaires à “Texte de format Python”

Questions similaires à “Texte de format Python”

Plus de réponses similaires à “Texte de format Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code