In computer languages, Python strings are commonly used. In actual application, if you are confused about Python strings, the following is a detailed description of the application process.
Alignment of Python strings in output:
- S.ljust(width,[fillchar])
# The output width is a string of characters, and the S is left aligned. The missing part is filled with fillchar. The default value is space.
- S.rjust(width,[fillchar]) #
Right alignment
- S.center(width, [fillchar]) #
In the center alignment S. zfill (width) # convert S to width length, and align it on the right. The missing part uses 0 to supplement the search and replacement in the string:
- S.find(substr, [start, [end]])
# Return the number of the first letter of substr in S. If S does not contain substr,-1 is returned. The functions of start and end are equivalent to searching in S [start: end ].
- S.index(substr, [start, [end]])
# It is the same as find (), but a runtime error is returned when S does not contain substr.
- S.rfind(substr, [start, [end]])
# Return the number of the first letter of the last occurrence of substr in S. If there is no substr in S,-1 is returned, that is, the first letter of the first occurrence of substr from the right.
- S.rindex(substr, [start, [end]])
- S.count(substr, [start, [end]]) #
Calculates the number of times that substr appears in S.
- S.replace(oldstr, newstr, [count])
# Replace oldstar with newstr in S, and count with the number of replicas. This is a common form of replacement, and some functions Replace special characters.