Trimmräume in Saitenpython
a = " yo! "
b = a.strip() # this will remove the white spaces that are leading and trailing
Super Stoat
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())
import re
s = '\n \t this is a string with a lot of whitespace\t'
s = re.sub('\s+', '', s)
sentence = ' hello apple'
sentence.strip()
>>> 'hello apple'
s = ' Hello World From Pankaj \t\n\r\t Hi There '
>>> s.replace(" ", "")
'HelloWorldFromPankaj\t\n\r\tHiThere'
s1 = ' abc '
print(f'String =\'{s1}\'')
print(f'After Removing Leading Whitespaces String =\'{s1.lstrip()}\'')
print(f'After Removing Trailing Whitespaces String =\'{s1.rstrip()}\'')
print(f'After Trimming Whitespaces String =\'{s1.strip()}\'')