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"
1lol = ' lol '
2print(lol)
3# normal output = lol
4lol = ' lol '
5print(lol.strip())
6# strip output = lol
7# Cool right
8
1lol = ' lol '
2print(lol)
3# normal output = lol
4lol = ' lol '
5print(lol.strip)
6# strip output = lol
7# Cool right
8