Strip, lstrip, and rstrip in python

Source: Internet
Author: User

Strip, lstrip, and rstrip in python

1. strip is the character specified in both ends. If it is not specified, spaces or tabs at both ends are deleted.

For example:

[Python] view plaincopy
  1. Print & quot; 123456 & quot;. strip ()
The result is 123456, because there is no space before and after [python] view plaincopy
  1. Print "123456". strip ("125 ")
Result 3456 # indicates to delete the ('1', '2', '5') [python] view plaincopy
  1. Printlen ("12345". strip ())
The result is 5, and the leading and trailing spaces are removed.

2. lstrip and rstrip remove the specified characters on the left and right respectively.

[Python] view plaincopy
  1. Print "1112345454". lstrip ("1245 ")
Result: 345454 [python] view plaincopy.
  1. Print "1112345454". rstrip ("1245 ")
Result 11123

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.