The Python strip () function and the use of the split function to summarize the __ function

Source: Internet
Author: User
Tags function prototype

Strip function prototype

Declaration: S is a string, RM is the sequence of characters to be deleted. You can only delete characters or strings that start or end. The middle character or string cannot be deleted.

S.strip (RM) deletes the character at the beginning and end of the s string that is in the RM delete sequence

S.lstrip (RM) deletes the character at the beginning of the S string at the RM delete sequence

S.rstrip (RM) deletes the character at the end of the S string that is in the RM delete sequence

Attention:

1. When RM is empty, the default deletion of whitespace characters (including ' \ n ', ' \ R ', ' \ t ', ')

For example:

2. The RM deletion sequence here is as long as the character on the edge (beginning or end) is deleted in the delete sequence.

For example:

Example:

Split usage of strings

Description
There is no character type in Python, only strings, where the character is a string that contains only one character ...

The split returns a list.

First, a common situation is listed, with no arguments, and the default is white space characters. As follows:

The results are:

1. Divide by one character, as '. '

1 2 3 4 str = (' www.google.com ') print str str_split = str. Split ('. ') print Str_split

The results are as follows:



2. Divide by one character and divide n times. If you press '. ' Split 1 times


1 2 3 4 str = (' www.google.com ') print str str_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.