Home  >  Article  >  Backend Development  >  Share a detailed explanation of the string function (partition) in Python

Share a detailed explanation of the string function (partition) in Python

零下一度
零下一度Original
2017-05-22 17:11:024437browse

The partition() function is mentioned here. What does it do? In fact, this function is similar to split, both of which are used for cutting.

partition(...)
    S.partition(sep) -> (head, sep, tail)
    
    Search for the separator sep in S, and return the part before it,
    the separator itself, and the part after it.  If the separator is not
    found, return S and two empty strings.

For example:

>>> a = 'changzhi1990'
>>> a.rpartition('h')
('changz', 'h', 'i1990')


You can see that a three-element tuple is returned, which is the string on the left side of 'h'. #, the separator 'h' itself, and the string to the right of the separator 'h'. Note: r means matching from right to left.

>>> a = 'changzhi1990'
>>> a.partition('h')
('c', 'h', 'angzhi1990')

Here is matching from left to right.

【Related recommendations】


1.

Example tutorial of partition string function in Python

2.

Share a string Example code of function (partition)

3.

MySQL-data table partition technology PARTITION code example analysis

The above is the detailed content of Share a detailed explanation of the string function (partition) in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn