1. Commonly used format symbols
% Symbol Usage List:
Format symbols |
Transformation |
%d |
Signed decimal integer |
%i |
Signed decimal integer, and automatically converts the octal (or hexadecimal) input into decimal
|
%u |
unsigned decimal integers |
%c |
Characters and their ASCII code |
%s |
String, formatted by a string conversion of STR () |
%o |
unsigned integer (octal) |
%x |
unsigned integer (hexadecimal) |
%x |
unsigned integer (16 uppercase characters) |
%e |
Floating-point numbers (scientific notation), lowercase E |
%E |
Floating-point numbers (scientific notation, E instead of e) |
%f |
Floating point number (with decimal point symbol) |
%g |
Floating-point numbers (%e or%f depending on the size of the value) |
%G |
Floating-point numbers (similar to%g) |
%p |
Pointer (memory address of the value printed in hexadecimal) |
%n |
Stores the number of output characters into the next variable in the parameter list |
%% |
Percent Sign |
2. Format () Formatting indicator Description
' B '-binary. The number is output as a base of 2. ' C '-character. Converts an integer to the corresponding Unicode string before printing. ' d '-decimal integer. The number is output as a base of 10. ' o '-eight binary. The number is output as a base of 8. ' x '-16 binary. The number is output in 16, and the number of digits above 9 is in lowercase letters. The ' e '-power symbol. Print numbers in scientific notation. Use ' e ' to indicate power. ' G '-general format. The value is output in fixed-point format. When the number is particularly large, it is printed in a power form. ' n '-number. When the value is an integer and ' d ', the values are the same as the ' G ' when they are floating-point numbers. The difference is that it inserts a numeric delimiter according to the locale. '% '-percent. Multiply the value by 100 and then print in fixed-point (' F ') format, followed by a percent semicolon.
3. Specify the alignment of the string for the desired length:
< (default) align Left> Right Alignment^ Middle Alignment= (for numbers only) after the decimal point
4.
Python_ Escape Character
Escape character |
Describe |
\ (at end of line) |
Line continuation character |
\\ |
Backslash symbol |
\‘ |
Single quotation marks |
\" |
Double quotes |
\a |
Bell |
\b |
BACKSPACE (Backspace) |
\e |
Escape |
\000 |
Empty |
\ n |
Line break |
\v |
Portrait tab |
\ t |
Horizontal tab |
\ r |
Enter |
\f |
Page change |
\oyy |
Octal number yy represents the character, for example: \o12 represents a newline |
\xyy |
The decimal number yy represents the character, for example: \x0a represents a newline |
\other |
Other characters are output in normal format |
Python formatted output print