This is the content of the December plan, beginning in January 2018 ~
If there is any mistake, please ask for it ~
Formatting this has been mentioned in print a little bit, and the truth is very similar to the C language.
% of the method:
%[(name)][flags][width]. [Precision]typecode
% c |
Convert to character (ASCII value, or string of length one) |
%r |
Prioritize string conversions with the repr () function |
%s |
Prioritize string conversions with the str () function |
%d/%i |
Turn signed decimal number |
%u |
Turn unsigned decimal number |
%o |
To unsigned octal number |
%x /%x |
Turns to unsigned hexadecimal number (x/x for the case of converted hexadecimal characters) |
%e/%e |
Turn scientific notation (e/e control output e/e) |
%f/%f |
Turns into floating-point numbers (fractional parts are naturally truncated) |
%g/%g |
%e and%f/%e and%f abbreviations |
% |
Output% (the format string includes a percent semicolon, so you must use a percentile) |
%r and%s are string conversions, so what's the difference?
1String ="hello\tworld\n"2 Print("%s"%string)3 Print("%r"%string)4 the string received by Hello World Str () is user-oriented5 6 'hello\tworld\n'Repr () The resulting string is machine-oriented
And most of the other symbols have been seen, here no longer explain
The Str.format () function replaces the previous "%" with "{}" and ":". Symbol.
[[Fill]align] [Sign] [#] [0] [Width] [,] [. Precision] [Type]
{} by location matching parameters, of course, do not write the default order, you can repeatedly appear
* What does "abc" mean to the function to speak, which is understood here as "abc" = ' A ', ' B ', ' C ' becomes
1 print ( " {1},{0},{2} . Format (*" ABC print ( " {1},{2},{0} . Format (" A , b , C ))
B,a,cb,c,a
{} Configuring parameters by name
1 Print ("{a},{b},{c}". Format (a=1,b='s', c=4))
1,s,4
{} configure parameters by subscript
1 alist=[ " s ", 2," c " print ( " {0[1]} . Format (alist)
alist=['s', 2,'C']print('{ 0[1]}'. Format (alist)#2
The above is also known as mapping list and dict
The next step is a series of {: XXXXXX} operations.
Python string formatting% with format () function IX