string.rstrip([chars])
-chars (optional): Specifies characters to remove from the end. Defaults to whitespace if omitted.
my_str='Plus2net '
output=my_str.rstrip()
print(output)
my_str='plus2net**'
output=my_str.rstrip('*')
print(output) # removes * from right
my_str='plus2net *#*#'
output=my_str.rstrip('*#')
print(output) # removes all right
Output is here
plus2net
plus2net
plus2net
Example
my_str='Plus2net'
output=my_str.rstrip('et')
print(output)
Output
Plus2n
my_str = ""
output = my_str.rstrip()
print(output) # Output: ''
text = "Hello, World! "
result = text.rstrip()
print(result)
Output:
Hello, World!
text = "plus2net***"
result = text.rstrip("*")
print(result)
Output
plus2net
text = "plus2net##@@"
result = text.rstrip("#@")
print(result)
Output
plus2net
text = "data.csv,,,,"
if text.endswith(","):
text = text.rstrip(",")
print(text)
Output
data.csv
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.