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)
1a = " smurf "
2
3a = a.strip()
4#remove space at begining and end of string
5print(a)
6#smurf