If you have any questions about Python string operations, you can click here. This article describes how to perform Python string operations. The following is a detailed introduction to the article, I hope you will gain some benefits after reading the following article.
Case-insensitive conversion of characters in a string:
- * S.lower()
Lowercase
- * S.upper()
Uppercase
- * S.swapcase()
Case-insensitive swap
- * S.capitalize()
Uppercase letters
- * String.capwords(S)
This is the method in the module. It separates S with the split () function, converts the first letter into upper-case letters with capitalize (), and finally merges them with join ().
- * S.title()
Only the first letter is in upper case, and the rest are in lower case. The module does not have the alignment of this method string in the 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])
Center alignment
- * S.zfill(width)
Change S to width length, and align it on the right. Fill the remaining part with 0.