Usage of python built-in string processing functions

Source: Internet
Author: User

1. lower (): converts all uppercase letters into lowercase letters. For example:

Copy codeThe Code is as follows:
Name = 'G'
B = name. lower ()

2. title ": converts a string into a title, that is, the first letter of all words in upper case, and the other letters in lower case. Same as lower ()

3. replace: returns the string obtained after all matching items of a string are replaced.

Copy codeThe Code is as follows:
'This is a test'. replace ('is ', 'are ')

4. split: splits strings into sequences.

Copy codeThe Code is as follows:
'1 + 2 + 3 + 4 + 5'. split ('+ ')

By default, all spaces are used as separators.

V. strip: returns a string that removes spaces on both sides (excluding the interior ).

Copy codeThe Code is as follows:
'In wh is kepy'. strip ()

6. translate: replace some parts of the string. The translate knowledge processes a single character. However, multiple replicas can be performed simultaneously. Multiple Replicas can replace a with B at the same time, and c with d. replace can only replace a with B at a time. The usage of translate is complex. If you need to use it, please refer to the documents that detail it.

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.