1, the format of the string:
Output as a new string according to the uniform specifications
2. Method of String Formatting: 1) Format method
Fomat () has two parameter positional parameters and keyword parameters enclosed in brackets {}
# {0}{1} is a positional parameter " {0} love {1}'. Format ("I""you") 'ILove you'
# {a}{b} is a keyword parameter >>> " {a} love {b} " . Format (a= " i ", B=" you " ) i Love you "
" {{1}} ". Format (" do not print " " print ")'{1 }'# The format method is invalidated after enclosing in brackets
2. Formatting operators for strings
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 floating-point numbers to specify the precision after a decimal point |
%e |
Format floating-point numbers with scientific notation |
%E |
function with%e, format floating-point numbers with scientific notation |
%g |
Use%f or%e depending on the size of the value |
%G |
function with%g, depending on the size of the value, use%f or%E |
' %c ' %97'a'
' %g '%1.11111111'1.11111 '
Python3 string Formatting