How to use rstrip() function to Remove the Last Element from the string In Python
The rstrip() is a Python function that returns a string copy after removing the trailing characters.
Python3
Str = "w3wiki" Str = Str .rstrip( Str [ - 1 ]) print ( Str ) |
GeeksForGeek
Python program to Remove Last character from the string
Given a string, the task is to write a Python program to remove the last character from the given string.
Example:
Input: “w3wiki”
Output: “GeeksForGeek”Input: “1234”
Output: “123”
Explanation: Here we are removing the last character of the original string.
Note: Strings are immutable in Python, so any modification in the string will result in the creation of a new string.