% for formatting strings, controlling the rendering format of strings
Example: print "I ' m%s,i ' m%d year old"% (' Vamei ', 99)
Results: I ' m vamei,i ' m.
Explanation: (' Vamei ', 99) Two elements ' Vamei ' and 99 are substituted for the true values of%s and%d,%s and%d are the format operators, the format operators are reserved for real values, and control the format of the display
Format operators:
%sConverted to a string, using the str () function to convert
%r converted to a string, using the Repr () function to convert
%c converted to a string of length one
%b converted to binary integers
%d converted to decimal integer
%i convert to decimal integer
%o Convert to eight-binary integer
percent conversion into character "%"
%x %x converted to hexadecimal integer
%e%e converted to exponent (base write E)
%f%f Convert to floating point
%g%g converted to exponential or floating-point numbers
Extension:%s and%r differences
Python string formatting operators