Python Common string processing

Source: Internet
Author: User

S.find (Substring,[start[end]]) #可指范围查找子串, returns the index value, otherwise returns-1

For example

>>>b = ' ABCD '
>>> b.find (' d ')
3
>>> b.find (' d ', 2,4)
3
>>> b.find (' d ', 3,4)
3

>>> b.find (' d ', 2, 3)
-1

Visible when the specified range is searched, the specified range is opened before closing.

S.index (Substring,[start[end]) #同find, just can't find the valueerror exception

S.count (Substring,[start[end]) #返回找到子串的个数

S.split (' * ') #将string转list, divided by *, for example:

>>> B = ' abc def GHI '
>>> B.split (")
[' abc ', ' Def ', ' Ghi ']

' * '. Join () #将list转string, with * link

For example:

>>> B = ' abc def GHI '
>>> B.split (")
[' abc ', ' Def ', ' Ghi ']
>>> C = B.split (")
>>> ' * '. Join (c)
' Abc*def*ghi '

Other uses are easier to understand, not to repeat

Python Common string processing

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.