1. String formatting
String formatting operator%+ conversion flag + Minimum field width + dot followed precision value + conversion type
The string module provides another way to format the from string import Template s=template (' $x. Glorious $x! ') S.substitute (x= ' Slim ')
Example: '%03.4f '% pi ' 3.1416 '
Prevent "label table" before field width and precision value The table can be 0, plus, minus, or space
Example: '%012.4f '% pi
' 0000003.1416 '
2. String method
2.1 String Constants
String.dights number 0-9
String.letters All Letters
String.lowercase All lowercase Letters
string.printable all printable characters
String.punctuation Strings for all punctuation
String.upercase All uppercase letters
2.2 String method
The Find method can find substrings in a longer string. Returns the leftmost index of the location of the substring, otherwise returns-1
Find can provide a starting and ending point, eg. Subject.find ("111", 0,16)
The Join method is used to add elements to the queue, which must be a string
Lower the lowercase master that returns a string
The Replace method is used to return a string after all occurrences of a string have been replaced
Split is used to split a string into a sequence, which is your method of join, and if you do not provide a delimiter, the program will use all the spaces as separators (spaces, tabulation, line wrapping, etc.)
The Strip method returns a string that strips both sides (excluding interior) spaces, or specifies the characters that need to be removed, and lists them as arguments
The Translate method can replace some parts of a string, but translate simply removes the single character. The advantage is that multiple substitutions can be made at the same time, sometimes more efficient than replace
Before the translate conversion, you need to complete a conversion table, using the From string import Maketrans, Maketrans has 2 parameters: two equal-length strings, representing each word in the 1th string nonalphanumeric the same position in the 2nd string substitution. The second parameter of the translate is optional and is used to specify the character to be deleted
Python Basic Tutorial Chapter 3rd--String