Python String Common functions

Source: Internet
Author: User

2017-07-03 23:26:08

1,. replace (self, old, new, count=-1)

The replace () function replaces the old string with the new string, and the last parameter, count, is optional, representing a maximum of count times (less than count).

Note that this substitution returns the replaced string, and the source string is unchanged.

s='ABCDEF'out =s.replace ('ef','EF  ')print(s)printoutput: Abcdefabcdef

2. Find (self, sub, start=0, end=len)

The Find () function returns the subscript index of the first character sub, which, by default, scans the entire string, but can set the start,end itself, consistent with the STL, where the starting interval is closed before opening.

Not found, return-1

s='ABCDEF'print(s.find ('BC', 0,1))  Print(S.find ('CD')) output:12

The. RFind () function is a right-to-left search, which returns the subscript of the sub string with the largest index value, or 1 if no search is made.

3.

Python String Common functions

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.