Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Remove Leading Whitespace From A Python String With .lstrip()

Calling `.lstrip()`` on a python string trims any leading whitespace (including newlines), while leaving any trailing whitespace untouched. For example:

Code

original = """

   hotel india juliett

    """

left_stripped = original.lstrip()

print(f"START|{left_stripped}|END")

Results

START|hotel india juliett

    |END