1# Python3 program to demonstrate the use of
2# strip() method
3
4string = " python strip method test "
5
6# prints the string without stripping
7print(string)
8
9# prints the string by removing leading and trailing whitespaces
10print(string.strip())
11
12# prints the string by removing strip
13print(string.strip(' strip'))
14Output:
15 python strip method test
16python strip method test
17python method test
1# removes outside whitespace/characters
2' hey '.strip() # "hey"
3' hey '.lstrip() # "hey "
4' hey '.rstrip() # " hey"
5'_.hey__'.strip('._') # "hey"
1txt = " test "
2
3txt.strip()
4#Output: "test"
5
6txt.lstrip()
7#Output: "test "
8
9txt.rstrip()
10#Output: " test"
1txt = ",,,,,rrttgg.....banana....rrr"
2x = txt.strip(",.grt")
3#outputs banana
4print(x)
1string = ' xoxo love xoxo '
2
3# Leading and trailing whitespaces are removed
4print(string.strip())
5
6# All <whitespace>,x,o,e characters in the left
7# and right of string are removed
8print(string.strip(' xoe'))
9
10# Argument doesn't contain space
11# No characters are removed.
12print(string.strip('stx'))
13
14string = 'android is awesome'
15print(string.strip('an'))