Remove String from Right in Python

  • Post category:String

In this article, you will see how to remove string from right in Python. The rstrip() method removes all trailing characters (characters at the end of a string) that match the characters specified in its argument.

Step 1: Create a string

str = "CodeAllow"
print("str = ", str)
print("str type = ", type(str))

Step 2: Remove string from right

print("Removed = ", str.rstrip("Allow"))


str =  CodeAllow
str type =  <class 'str'>
Removed =  Code

Free resources to learn advanced skills: AiHints and CodeAllow