0
Q:

strip python

string = "        This is a string         "
string = string.strip()
print(string)
3
>>> s.strip()
'Hello  World   From Pankaj \t\n\r\tHi There'
4
# Python3 program to demonstrate the use of 
# strip() method   
  
string = " python strip method test " 
  
# prints the string without stripping 
print(string)  
  
# prints the string by removing leading and trailing whitespaces 
print(string.strip())    
  
# prints the string by removing strip 
print(string.strip(' strip')) 
Output:
 python strip method test 
python strip method test
python method test
11
" dog".trim() //"dog"
2
# removes outside whitespace/characters
'  hey  '.strip()     # "hey"
'  hey  '.lstrip()    # "hey  "
'  hey  '.rstrip()    # "  hey"
'_.hey__'.strip('._') # "hey"
6
txt = "     banana     "
x = txt.strip()
#x will be "banana"
7
txt = "  test    "

txt.strip()
#Output: "test"

txt.lstrip()
#Output: "test    "

txt.rstrip()
#Output: "  test"
4
txt = ",,,,,rrttgg.....banana....rrr"
x = txt.strip(",.grt")
#outputs banana
print(x)
3

New to Communities?

Join the community