Case-insensitive conversion of Characters During Python string processing functions

Source: Internet
Author: User

If you are not familiar with Python string processing functions, you can use the following articles to understand the actual operations related to Python string processing functions. The following is a detailed introduction to the article, I hope you will gain some benefits after reading the following articles.

Python string processing functions. There are various string operation functions in python. In history, the string class experienced a cycle in python. At the very beginning, python had a special string module. To use the string method, we had to import it first. However, due to the suggestions of many python users, we started from python2.0, the string method is changed to S. method (), as long as S is a string object, it can be used in this way, without the need for import.

At the same time, to maintain backward compatibility, the current python still retains a string module, and the defined method and S. method () is the same, and all these methods finally point to S. note that S. method () can call more methods than the string module. For example, isdigit () and istitle () can only use S. method.

  • Three steps to implement the Python RUD Function
  • Python module compilation steps
  • How to read and write configuration files in Python
  • Related to the three advantages of Python programming in practical application
  • In which software can the Python language be developed?

For a String object, the first thought of operation may be to calculate the number of characters it contains, and it is easy to think of S. len (), but this is wrong. It should be len (S ). Because len () is a built-in function, including in the _ builtin _ module. Python does not include len () in the string type. At first glance, it seems a bit incomprehensible. In fact, everything has its own logic.

Len () can calculate not only the number of characters in a string, but also the number of list members and the number of tuple members. Therefore, it is inappropriate to calculate len () in a single string, therefore, len () can be used as a general function, and different types of operations can be implemented with heavy loads. In addition, a len () can be included in each type of len () operation () function. Python chooses the first solution. Similarly, the str (arg) function represents arg in the string type.

Case-insensitive conversion of characters in a string:

 
 
  1. S.lower()    
  2. S.upper()   
  3. S.swapcase()   
  4. S.capitalize()   
  5. 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() 

This method is not available in the module.


 

Related Article

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.