Common python string processing and python string processing

Source: Internet
Author: User

Common python string processing and python string processing

S. find (substring, [start [end]) # searches for substrings in the specified range and returns the index value. Otherwise,-1 is returned.

For example

>>> B = 'abc'
>>> B. find ('D ')
3
>>> B. find ('D', 2, 4)
3
>>> B. find ('D', 3,4)
3

>>> B. find ('D', 2, 3)
-1

It can be seen that when a range is specified for search, the specified range is open before closing.

S. index (substring, [start [end]) # Same as find, but the ValueError is not found.

S. count (substring, [start [end]) # returns the number of substrings found.

S. split ('*') # convert string to list and separate it with *. For example:

>>> B = 'abc def ghi'
>>> B. split ('')
['Abc', 'def ', 'ghi']

'*'. Join () # convert list to string and use * to link

For example:

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

Other usage is easy to understand and will not be described here

 

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.