Python

Python Menu

Python

Python String rsplit() - Definition, Syntax, Parameters, Examples

Definition

The rsplit() method splits a string into a list, starting from the right. If no "maxsplit" is specified, this method will return the same as the split() method. Note that when maxsplit is specified, the list will contain the specified number of elements plus one.

Syntax

string.rsplit(separator, maxsplit)

Parameters

Parameter Description
separator Optional. Specifies the separator to use when splitting the string. By default any whitespace is a separator
maxsplit Optional. Specifies how many splits to do. Default value is -1, which is "all occurrences"

Examples:

fruits = "apple, banana, cherry, orange" result = fruits.rsplit(", ") print(result) # using the maxsplit parameter fruits = "apple, banana, cherry, orange" result = fruits.rsplit(", ", 2) print(result)

Introduction

Python Basics

Python Advance

Data Science Python Tutorials

Python Functions and Methods