Python String rstrip() Method

Last Updated : 31 Dec 2025

Python rstrip() method removes all the trailing characters from the string. It means it removes all the specified characters from right side of the string. If we don't specify the parameter, It removes all the whitespaces from the string. This method returns a string value.

Syntax of Python String rstrip() Method

It has the following syntax:

Parameters

  • chars: character to be removed from the string.

Return

It returns string.

Different Examples for Python String rstrip() Method 

Let's see some examples of rstrip() method to understand it's functionality.

Example 1

A simple example, does not take any parameter. It removes all the trailing whitespaces from the string.

Output:

Old string:  Python and C# 
New String:  Python and C#

Example 2

string chars are removed based on the char type parameter. It returns a string after removing the character.

Output:

Old string:  Python and C#
New String:  Python and C

Example 3

It is pretty easy to know how many characters are removed by getting string length. See the example. String length is displayed along with string value.

Output:

Old string:  Python and C# 11
New String:  Python and C 10
 
Next TopicPython Strings