Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to Strip whitespace in python

s = '   This is a sentence with whitespace.       
'

print('Strip leading whitespace: {}'.format(s.lstrip()))
print('Strip trailing whitespace: {}'.format(s.rstrip()))
print('Strip all whitespace: {}'.format(s.strip()))

# Output

# Strip leading whitespace: This is a sentence with whitespace.       
# Strip trailing whitespace:    This is a sentence with whitespace.
# Strip all whitespace: This is a sentence with whitespace.
Source by www.kdnuggets.com #
 
PREVIOUS NEXT
Tagged: #How #Strip #whitespace #python
ADD COMMENT
Topic
Name
6+3 =