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
1lol = ' lol '
2print(lol)
3# normal output = lol
4lol = ' lol '
5print(lol.strip())
6# strip output = lol
7# Cool right
8
1a = " smurf "
2
3a = a.strip()
4#remove space at begining and end of string
5print(a)
6#smurf
1# Leading and trailing whitespaces are removed
2text1 = ' Python Programming '
3print(text1.strip())
4
5
6# Remove the whitespace and specified character on
7# both leading and trailing end
8text3 = ' code its my code '
9print(text3.strip(' code'))
10
11# Remove the specified character at
12# both leading and trailing end
13text2 = 'code its my code'
14print(text2.strip('code'))
1lol = ' lol '
2print(lol)
3# normal output = lol
4lol = ' lol '
5print(lol.strip)
6# strip output = lol
7# Cool right
8