home
NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

Remove Leading And Trailing Whitespace From A Python String With .strip()

Calling .strip() on a string removes both leading and trailing whitespace (including newline characters)

October 2023
Code
original = """

    alfa bravo charlie

   """

stripped = original.strip()

print(f"START|{stripped}|END")
Results
START|alfa bravo charlie|END
═══ § ═══