1#!/usr/bin/python
2
3str = " this is string example....wow!!! ";
4print str.rstrip()
5str = "88888888this is string example....wow!!!8888888";
6print str.rstrip('8')
7
8#the answer
9
10#this is string example....wow!!!
11#88888888this is string example....wow!!!
1text = " Apple "
2x = txt.rstrip()
3>>> ' Apple'
4x.rstrip('e')
5>>> ' Appl'
6x.lstrip()
7>>> 'Apple'
1text = " hello "
2
3text = text.lstrip() # lstrip == left strip
4>>> ' hello'
5
6text = text.rstrip() # rstrip == right strip
7>>> 'hello '
8
9text = text.strip() # strip == strip from both sides
10>>> 'hello'
1#python3 program of rstrip method with optional argument
2s = "Hello There "
3a = "s"
4print(s.rstrip()) # prints s without any spaces at the end
5print(s.rstrip(a)) # prints s without any characters of value a at the end
1
2 txt = " banana "
3
4x =
5 txt.rstrip()
6
7
8 print("of all fruits", x, "is my favorite")