English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
rstrip() method deletes the specified characters (default is space) from the end of the string.
rstrip() removes characters from the right according to the parameter (a string specifying the set of characters to be removed).
The syntax of rstrip() is:
string.rstrip([chars])
chars (optional)-A string that specifies the set of characters to be removed.
If no chars parameter is provided, all spaces on the right 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 end of the string until the first non-matching.
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