String formatting symbolic meaning
Symbol |
Description |
%c |
Formatting characters and their ASCII code |
%s |
formatting strings |
%d |
formatting integers |
%o |
Formatting an unsigned octal number |
%x |
formatting unsigned hexadecimal numbers |
%x |
Format unsigned hexadecimal number (uppercase) |
%f |
Format fixed-point number to specify the precision after the decimal point |
%e |
Format fixed-point numbers with scientific notation |
%E |
function with%e, format fixed-point number with scientific notation |
%g |
Depending on the size of the value, use%f live%e |
%G |
function with%g, depending on the size of the value, use%f or%e |
How to use:
Only one Empty time: print (' xxxx%c '%97)
Multiple Empty Hours: print ('%c%c%c '% (97, 98, 99) need to use tuples
Formatting operator Auxiliary directives
Symbol |
Description |
M.n |
M is the smallest total width displayed, and n is the number of digits after the decimal point |
- |
Use to align Left |
+ |
Show plus sign (+) in front of positive number |
# |
Display ' 0o ' before octal number, ' 0x ' or ' 0X ' before hexadecimal number |
0 |
The displayed number is preceded by a fill of ' 0 ' instead of a space |
How to use:
M.n:print ('%5.5F '% 27.55), at this time, there are 5 digits after the decimal point, if insufficient will automatically complete, get: ' 27.55000 '
-: Print ('%-010d '%27.55), at this time without the '-' number, will be: ' 0000000027 ', if there is '-', then get: ' 27
' #: Print ('% #o '%12), easy to understand, converted to 8 or 16 input output
String escape character meaning
Symbol |
Description |
\‘ |
Single quotation marks |
\" |
Double quotes |
\a |
Issue System ring tones |
\b |
Backspace |
\ n |
Line break |
\ t |
Horizontal tab (tab) |
\v |
Portrait tab |
\ r |
Carriage return character |
\f |
Page break |
\o |
Characters represented by octal numbers |
\x |
The hexadecimal number represents the character |
/ |
Represents a null character |
\\ |
Back slash
|
Reprinted from FISHC Forum: http://bbs.fishc.com/thread-39140-1-1.html
Python string formatting symbolic meaning and meaning of escape characters