1, for the encoding of a single character, Python provides a ord() function to get the integer representation of the character, the chr() function converts the encoding to the corresponding character:
2. To calculate str how many characters are included, you can use a len() function:
3, the len() function calculates the str number of characters, if replaced bytes , the len() function calculates the number of bytes:
Formatting and placeholder
Use% as a placeholder in Python, including the following types:
%d integral type
%s string
%f floating Point
%x 16 binary integer
Where%d can be preceded by a number or 0 to indicate the number of integers and whether the preceding 0:
%s can convert any type of data to a string
If% is not a placeholder, just a normal string, use percent
Practice
Xiao Ming's score from last year's 72 points to 85 points this year, please calculate the percentage of small Ming performance increase, and use the string format ‘xx.x%‘ to show that only 1 digits after the decimal point
1 # string-related exercises: Xiao Ming's achievements from last year's 72 points to the 85 points this year, 2 # Please calculate the percentage of the increase in Xiao Ming's grade, and display the ' xx.x% ' in string format, leaving only 1 digits after the decimal point 3 old=724 new=855 pre= (new-old)/old6print(PRE) 7print(' Xiao Ming grades improved%.1f%%' % (pre))
Printing results are:
0.18055555555555555 Xiao Ming's grades increased by 0. 2%
Python Learning Record (vii)------python string