This article summarizes some simple and basic formats of output formatting. I will not talk about them here. let's take a look at the details. 1. print the string & gt; print & quot; Im % s & quot; % (& quot; jihite & quot ;) imjihite 2. print integer & gt; print & quot; Im % dyearsold & quot; % (17) Im17yearsold 3. print floating point & gt; & gt; print & quot; π % f & quot; % (3.1415926) π 3 This article summarizes some simple and basic output formatting formats, let's take a look at the detailed introduction.
I. print strings
>>> print "I'm %s" % ("jihite")I'm jihite
II. print the integer
>>> print "I'm %d years old" % (17)I'm 17 years old
3. print floating point numbers
>>> print "π=%f" % (3.1415926)π=3.141593
4. print the floating point number (specify the number of decimal points to be retained)
>>> print "π=%.3f" % (3.1415926)π=3.142
5. specify the placeholder width
>>> print "NAME:%8s AGE:%8d WEIGHT:%8.2f" % ("jihite", 17, 62.2)NAME: jihite AGE: 17 WEIGHT: 62.20
6. specify the placeholder width (left aligned)
>>> print "NAME:%-8s AGE:%-8d WEIGHT:%-8.2f" % ("jihite", 17, 62.2)NAME:jihite AGE:17 WEIGHT:62.20
7. specify a placeholder (only 0 can be used as a placeholder)
>>> print "NAME:%-8s AGE:%08d WEIGHT:%08.2f" % ("jihite", 17, 62.2)NAME:jihite AGE:00000017 WEIGHT:00062.20
8. Scientific notation
>>> format(0.0000023, '.2e')'2.30e-06'>>> format(0.23, '.2e')'2.30e-01'
The above is a detailed description of the common causes of formatting output using python. For more information, see other related articles in the first PHP community!