Changes in uppercase and lowercase letters in Python strings

Source: Internet
Author: User

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:

 
 
  1. * S.lower()  

Lowercase

 
 
  1. * S.upper()   

Uppercase

 
 
  1. * S.swapcase()  

Case-insensitive swap

 
 
  1. * S.capitalize() 

Uppercase letters

 
 
  1. * 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 ().

 
 
  1. * 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:

 
 
  1. * 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.

 
 
  1. * S.rjust(width,[fillchar])   

Right alignment

 
 
  1. * S.center(width, [fillchar])  

Center alignment

 
 
  1. * S.zfill(width) 

Change S to width length, and align it on the right. Fill the remaining part with 0.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.