Python's method of removing a hollow lattice of strings

Source: Internet
Author: User

Tag: Split expression specifies regular log pos space out character

1.strip (): Remove the blanks from the head and tail

2.lstrip (): Remove the left space

3.rstrip (): Remove the space on the right

4.replace (' C1 ', ' C2 '): Replace the C1 in the string with C2. So you can use replace (",") to remove all the spaces in the string.

5.split (): The string is sliced by specifying a delimiter, and only the NUM substring is delimited if the parameter num has a specified value

IN[2]: a='ddd DfE DFD efre ddd'in[3]: aout[3]:'ddd DfE DFD efre ddd'in[4]: A.strip () out[4]:'ddd DfE DFD efre ddd'in[5]: A.lstrip () out[5]:'ddd DfE DFD efre ddd'in[6]: A.rstrip () out[6]:'ddd DfE DFD efre ddd'in[7]: A.replace (' ',"') out[7]:'ddddfedfdefreddd'in[8]: A.split () out[8]: ['DDD','DfE','DFD','Efre','DDD']

6. Using Regular expressions

Re.split (R'\s+"a b   c') ['a ' ' b ' ' C ']

Python's method of removing a hollow lattice of strings

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.