How to remove leading whitespace in Python?
This tutorial is How to remove leading whitespace in Python?. I am use python buil-in The lstrip() method will remove beginning whitespaces, newline and tab characters on a string beginning.
lstrip
Example
str = ' How to remove leading whitespace in Python? ' str.lstrip() Output: 'How to remove leading whitespace in Python? '
rstrip
rstrip() remove ending whitespace use the rstrip() function to remove ending whitespace in the same manner.
Example
str = ' How to remove leading whitespace in Python? ' str.rstrip() Output: ' How to remove leading whitespace in Python?'
strip
strip() remove beginning and ending whitespace use the strip() function to remove both trailing and leading whitespace in the same manner.
Example
str = ' How to remove leading whitespace in Python? ' str.strip() Output: 'How to remove leading whitespace in Python?'