Change language

Python String | rpartition ()

| | |

Syntax :

 string.rpartition (separator) 

Parameters :

  separator -  separates the string at the first occurrence of it. 

Return value:

  1. It returns the part of the string before the separator , the delimiter parameter itself and the part after the delimiter if a delimiter parameter is found in the string.
  2. It returns two blank lines followed by the given string if no delimiter is found in the string.

Exception :

 If separator argument is not supplied, it will throw TypeError. 

Code # 1:

# Python3 code explaining rpartition ()

 
# The line must be split

string1 = "Geeks @ for @ Geeks @ is @ for @ geeks"

 

string2 = "Ram is not eating but Mohan is eating"

 
# Here & # 39; @ & # 39; - separator

print (string1.rpartition ( ’@’ ))

 
# Here & # 39; is & # 39; is the delimiter

print (string2.rpartition ( ’ is’ ))

Output:

 (’Geeks @ for @ Geeks @ is @ for’,’ @ ’,’ geeks’) (’Ram is not eating but Mohan ’,’ is’, ’eating’) 

Code # 2:

# Python3 code explaining rpartition ()

 
# The line must be split

string = "Sita is going to school"

 
# Here “not” is a separator that is not
# appears on this line

print (string.rpartition ( ’not’ ))

Output:

 (’’, ’’, ’Sita is going to school’) 

Code # 3: TypeError

# Python3 code explaining TypeError
# in rpartition ()

 

str = "Bruce Waine is Batman"

 
# Nothing is transferred as separator

print ( str . rpartition ())

Output:

 Traceback (most recent call last): File "/home/e207c003f42055cf9697001645999d69.py", line 7, in print (str.rpartition ()) TypeError: rpartition () takes exactly one argument (0 given) 

Code # 4: ValueError

# Python3 code explaining ValueError
# in rpartition ()

 

str = "Bruce Waine is Batman"

 
# Nothing is passed as separator

print ( str . rpartition (""))

Exit d:

 Traceback (most recent call last): File "/home/c8d9719625793f2c8948542159719007.py", line 7, in print (str.rpartition ("")) ValueError: empty separator 

Python String | rpartition () File handling: Questions

Python String | rpartition () partition: Questions

Shop

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method