Python:strip (), Split ()

Source: Internet
Author: User

1. Strip () function

Strip () is the deletion of the characters inside the ' () ', and when () is empty, the default is to remove the whitespace (including ' \ n ', ' \ R ', ' \ t ', ')

(1) S.strip (RM) Remove the characters from the beginning and end of the s string in the RM delete sequence

(2) S.lstrip (RM) Delete the character at the beginning of the S string in the RM delete sequence

(3) S.rstrip (RM) Delete the character at the end of the s string in the RM delete sequence

2. Split function

Split is a split function that splits a string into a "character" and is saved in a list.

1 a='a b c d'2 b=a.split ()3print(b)

Output: [' A ', ' B ', ' C ', ' d ']

The default is a space split with no parameters. The reason for the "character" of double quotes, because the actual Python does not have characters.

Split with parameters according to actual requirements

1 ' www.baidu.com ' 2 B = a.split ('. ' )3print(b)

Output: [' www ', ' Baidu ', ' com ']

You can also take a number parameter, which means "cut a few knives"

1 ' www.baidu.com ' 2 B = a.split ('. ', 1)# with. Cut 1 knives, divided into 2 pieces 3print(b)

Output: [' www ', ' baidu.com ']

Python:strip (), Split ()

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.