string manipulation of Python

Source: Internet
Author: User

1. Modify the case

(1) Title () displays each word in uppercase, with the first letter of each word capitalized. This is useful,

Because you often need to treat your name as information. For example, you might want the program to treat the value Ada, Ada, and Ada as the same name,

and show them all as Ada

(2) Upper ()/lower () to change the string to all uppercase or all lowercase,

Where data is stored, method lower () is useful. Many times, you can't rely on users to provide the right case, so

You need to convert the strings to lowercase first, and then store them. When you need to display this information later, convert it to the most appropriate large

lowercase mode.

2. Merging (splicing)

Python uses a plus sign (+) to combine characters, and this method of merging strings is called stitching. By stitching, you can use the information stored in a variable to create a complete message.

3. Use line breaks or tabs to add whitespace

To add a tab, you can use the character combination \ t.

To add line breaks, use the character combination \ n.

4. Delete blank

You can use the Rstrip () function to find extra whitespace at the beginning and end of a string. Make sure there is no white space at the end of the string.

Only temporary, not permanently deleted.

You can also use the method Lstrip () and strip () to remove whitespace at the beginning or both ends.

string manipulation of Python

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.