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
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.