string =' abc ' # After removing leading whitespace print(string.lstrip()); # Output: 'abc ' # After removing trailing whitespace print(string.rstrip()); # Output: ' abc' # After removing all whitespace print(string.strip()); # Output: 'abc'
>>> s.strip() 'Hello World From Pankaj \t\n\r\tHi There'
s = ' Hello World From Pankaj \t\n\r\t Hi There ' >>> s.replace(" ", "") 'HelloWorldFromPankaj\t\n\r\tHiThere'
sentence = ' hello apple' sentence.strip() >>> 'hello apple'
st = " a " strip(st) #Output : "a"
a = " yo! " b = a.strip() # this will remove the white spaces that are leading and trailing
## Remove the Starting Spaces in Python string1=" This is Test String to strip leading space" print (string1.lstrip())