Python rpartition() Method

Python 字符串Python String


Description

The rpartition() method is similar to thepartition()method, except that this method starts searching for the separator from the end (i.e., the right side) of the target string.

If the string contains the specified separator, it returns a 3-element tuple: the first element is the substring to the left of the separator, the second is the separator itself, and the third is the substring to the right of the separator.

Syntax

Syntax of the rpartition() method:

str.rpartition(str)

Parameters

str : The specified separator.

Return Value

Returns a 3-element tuple: the first is the substring to the left of the separator, the second is the separator itself, and the third is the substring to the right of the separator.

Example

The following example demonstrates the use of the rpartition() method:

Example (Python 2.0+)

#!/usr/bin/python str = "www.example.com" print str.rpartition(".")

The output result is:

('www.example', '.', 'com')

Python 字符串Python String

Other Extensions