English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
rstrip() method removes the specified characters (default is space) at the end of the string.
rstrip() removes characters from the right side according to the parameter (a string specifying the set of characters to be deleted).
The syntax of rstrip():
string.rstrip([chars])
chars (optional)-A string specifying the set of characters to be deleted.
If no chars parameter is provided, all spaces on the right side of the string are removed.
rstrip() returns a copy of the string with the trailing characters removed.
chars remove all combinations of characters from the right side of the string until the first mismatch.
random_string = ' this is good' # Remove leading whitespace print(random_string.rstrip()) # The parameter does not contain 'd' # Do not delete any characters. print(random_string.rstrip('si oo')) print(random_string.rstrip('sid oo')) website = 'www.w'3codebox.com/' print(website.rstrip('m/.'))
When running the program, the output is:
this is good this is good this is g www.w3codebox.co