Get the App
SLTechnology News&Howtos  ›  Development  › 

Conversion of uppercase and lowercase characters in Python strings

Shulou Source: shulou.com Published: 2022-06-03 11:41:54 09月21日 Update

This article mainly introduces "uppercase and lowercase conversion of characters in Python string". In daily operation, I believe many people have doubts about the conversion of uppercase and lowercase characters in Python string. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "uppercase and lowercase conversion of characters in Python string". Next, please follow the editor to study!

Transformation of the case of characters in a string:

* S.lower ()

Lowercase

* S.upper ()

Uppercase

* S.swapcase ()

Case swapping

* S.capitalize ()

Initials are capitalized

* String.capwords (S)

This is the method in the module. It separates S with the split () function, then capitalizes the initials with capitalize (), and merges it with join ().

* S.title ()

Only the first letter is uppercase and the rest is lowercase. There is no alignment of this method string on output in the module:

* S.ljust (width, [fillchar])

Output width characters, S left-aligned, the insufficient part is filled with fillchar, the default is space.

* S.rjust (width, [fillchar])

Align right

* S.center (width, [fillchar])

Middle alignment

* S.zfill (width)

Change S to width length, align it on the right, and make up for the deficiency with 0.

At this point, the study of "uppercase and lowercase conversion of characters in Python strings" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Characters uppercase string lowercase learning letters methods size more modules parts help output utility and then functions only articles theory knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi Apple Huawei Xiaomi