Python: Split a string on the last occurrence of the delimiter| split string last occurrence python

Python Split a string on the last occurrence of the delimiter

Write a python program to split a string on the last occurrence of the delimiter.

Program:-

str1 = "s,i,r,f,p,a,d,h,a,i"
print(str1.rsplit(',' , 1)
print(str1.rsplit(',' , 2)
print(str1.rsplit(',' , 5)

Output:-

's,i,r,f,p,a,d,h,a','i'
's,i,r,f,p,a,d,h', 'a','i'
's,i,r,f,p', 'a', 'd', 'h', 'a','i'

Previous articlePrime Number Program in Java | Write a program to print Prime Number Program in Java.
Next articlePython: Move all spaces to the front of a given string in single traversal

LEAVE A REPLY

Please enter your comment!
Please enter your name here