How to remove all leading whitespace in string in Python?

PythonServer Side ProgrammingProgramming

The lstrip() method will remove leading whitespaces, newline and tab characters on a string beginning. You can use it in the following way:

>>> '     hello world!'.lstrip()
'hello world!'

You can also use the strip() function to remove both trailing and leading whitespace in the same manner. For example:

>>> '     hello world!    '.strip()
'hello world!'
raja
Published on 11-Dec-2017 14:52:36
Advertisements