How to Use String rsplit() Method in PythonPython Basics


The rsplit() method splits string from the right at the specified separator and returns a list of strings. If no separator is specified, any whitespace string is a separator.

Example

# !/usr/bin/python3

S = "this is an example....!!!"
print(S.rsplit())
print(S.rsplit('i', 1))
print(S.rsplit('w'))

Output:

['this', 'is', 'an', 'example....!!!']
['this ', 's an example....!!!']
['this is an example....!!!']

Syntax

str.rsplit([separator [, maxsplit]])

Parameters

Name Description
separator The is a delimiter
maxsplit Defines the maximum number of splits

Return Value

It returns a list of strings.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us