67 of 151 menu

The rpartition method

The rpartition method returns a tuple of a string split by the last match of a substring and the specified delimiter parameter.

Syntax

string.rpartition(separator)

Example

Let's apply the rpartition method to the following line:

txt = 'abc_dea' print(txt.rpartition('_'))

Result of code execution:

('abc', '_', 'dea')

Example

Now let's add an extra character '_' to our string and apply the rpartition method again:

txt = 'ab_cd_ea' print(txt.rpartition('_'))

As can be seen from the obtained result, the method split the string only by the last match of the character '_':

('ab_cd', '_', 'ea')

See also

  • method join,
    which returns a string from a list of strings
  • method partition,
    which divides a string by the first match of a substring
  • method rsplit,
    which divides a string by the substring on the right
  • method split,
    which divides a string by the substring on the left
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline