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

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

零下一度
Release: 2017-05-22 17:11:02
Original
4476 people have browsed it

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.
Copy after login

For example:

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


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')
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template