×

Python String rsplit() method

Python String rsplit() method

The string.rsplit() method in Python splits a string into a list, starting from the right. If the "max" parameter is not specified, this method will return the same output as the string.split() method.

Syntax

string.rsplit([sep [,maxsplit]])

Parameter

sep (optional): This parameter specifies the separator to use when splitting the string. The default value is whitespace.

maxsplit (optional): This parameter Specifies how many splits to do. The default value is -1, which is "all occurrences".

Return

This method returns a list of the words in the string, using sep as the delimiter string. 

Example 1

 # Python program explaining
 # the string.rsplit() method
 # initializing the string
 string = "Python Java C# Ruby"
 print("Original string...")
 print(string)
 # spliting the string when whitespaces ocures
 print("After spliting the string …")
 print(string.rsplit()) 

Output

 Original string...
 Python Java C# Ruby
 After spliting the string... 
 ['Python', 'Java', 'C#', 'Ruby'] 

Example 2

 # Python program explaining
 # the string.rsplit() method
 string = "Tutorials and Examples"
 # By default this method Splits at space
 print(string.rsplit()) 
 # Splits at 'g'. As the maximum limit as 1. So 
 # from right, the splitting occurs at second t 
 string = "Tutorials, and, Examples"
 print(string.rsplit('t', 1)) 
 # Splitting at '$' with maximum splitting 
 # as 1 
 string = "Tutorials$and$Examples"
 print(string.rsplit('$', 1)) 

Output

 ['Tutorials', 'and', 'Examples']
 ['Tu', 'orials, and, Examples']
 ['Tutorials$and', 'Examples'] 

Related Topics

os.rename() method in Python

In Python, the os module provides the capacity to interact with the operating system. The operating system comes under the Python module. In this module, Python provides a specific feature...

3 minutes read.

Python str() function

Python str() function The str() function in Python converts the specified value into a string. Syntax class str(object='')           or class str(object=b'', encoding='utf-8', errors='strict') Parameter object:  This parameter represents any object to convert the given...

1 minute read.

How to print in same line in python

How to Print in the Same Line in Python To print in Python, we use the print () function and the syntax of print () goes like this: print (values, sep =...

3 minutes read.

Crash Course on Python by Google

There is a new, free Python programming course offered by Google on Coursera. No programming experience is necessary. There are numerous Python courses available, but when you learn that Google is...

5 minutes read.

Create Table Using PyQt5 in Python

PyQt5: PyQt5 is one of several solutions that Python offers for creating GUI applications. Cross-platform GUI toolkit PyQt5 is a collection of Python interfaces for Qt version 5. With this library's...

4 minutes read.

How to Download Python

How to Download Python Python is the most renowned programming language and developers across the globe are working on projects that are made using Python and its libraries. Here we will...

4 minutes read.

Python Line Break

Introduction In this tutorial, you will learn line breaks in python.In Python, the new line character is used to indicate the start of a new line and the end of an...

5 minutes read.

Kite Python

Kite in Python: The Kite is a package provided by the python programming language; it works with the help of artificial intelligence and helps us write code inside the visual studio....

3 minutes read.

Python Graph

Python Graph: In Computer Science and Mathematics, a Graph is a pictorial representation of a group of objects or elements where some elements are connected using the links. A graph...

5 minutes read.

Syntax of Map function in Python

In this tutorial, we will understand what the map function in Python is meant. Further, we will see the syntax to be used for the same in python language. We...

3 minutes read.

Scraping data in python

Data scraping is a technique in which one program extracts a set of data from the output of another program. Web scraping is the most common application of this technique....

6 minutes read.

Joint Plot in Python

Introduction to Joint plots: The joint plot is the finest approach to evaluate both the specific distribution of each variable and also the connection between the two variables. Three different plots make...

4 minutes read.

Python Encapsulation

What is meant by Encapsulation? The process of restricting access to the methods and variables so that accidental modification of data can be prevented is known as Encapsulation. The motive of Encapsulation:...

3 minutes read.

Looping through Data Frame in Python

Iterate over Rows and Columns in Pandas Dataframe This tutorial aims to make us understand what Pandas in Python are, what Data Frame in Python is and its significance, what are...

4 minutes read.

How to make API calls in Python

Information is extremely critical these days since it drives applications and organizations. It is subsequently critical to figure out how to get this information to serve your application. In fundamental...

4 minutes read.

Python Key Error

What is an Error? Errors are nothing but problems in the program which occur in a program code, and this will stop the execution of the program. It is also called...

6 minutes read.

Python program to print calendar

Python program to print the calendar This article will explain how to print the calendar of month and year using Python's calendar module. It's a straightforward thing in Python by importing...

1 minute read.

How to check version of Python

How to check version of python The versions of Python come with different kinds of features and functionalities. It is not a herculean task to keep track of the updates these...

3 minutes read.

Python List index() method

Python List index() method The list.index () method in Python returns the position at the first occurrence of the specified value. Syntax list.index(x[, start[, end]]) Parameter element – This parameter represents the element whose lowest index will be returned. start (Optional)...

2 minutes read.

apply() function in python

Pandas: Pandas is a library in python. It is an open source package in python. Pandas in python are used for data cleaning and data analysis. Data frame mainly consists of...

3 minutes read.