Python string formatting symbol meaning and escape character meaning

1. Meaning of string formatting symbol
% c Format character and its ASCII code
% s Format string
% d Format integer
% o Format unsigned octal integer
% x Format unsigned hexadecimal integer
% X Format Unsigned hexadecimal integer (uppercase)
% f Format fixed-point number, you can specify the precision after the decimal point
% e Use scientific notation to format fixed-point number
% E Same as% e, use scientific notation to format fixed-point number
% g decides to use% f or% e
according to the size of the value% G acts the same as% g, decides to use% f or% e according to the size of the value
2, the formatting operator auxiliary instruction
mn m is the minimum total width of the display, n is the decimal Number of digits behind
-used for left alignment
+ display + sign before a positive number
# Display zero (0) in front of an octal number, and 0X or 0x
0 in front of a hexadecimal number Fill the displayed number with 0 to replace spaces
3. Meaning of string escape characters
\ 'single quote
\ "double quote
\ a system ringtone
\ b backspace character
\ n line feed
\ t horizontal tab character (TAB)
\ v vertical tab character
\ r carriage return Fu
\ f formfeed
character \ o octal number represented by the
\ character hexadecimal number represented by x
\ 0 represents a Character
\\ backslash

Published 38 original articles · Like 29 · Visits 10,000+

Guess you like

Origin blog.csdn.net/weixin_45270982/article/details/104240268