Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Remove Trailing Whitespace From A Python String With .rstrip()

Call [TODO: Code shorthand span ] on a python string to remove any trailing whitespace (including newline characters). For example, this text has both leading and trailing whitespace and newlines. Calling [TODO: Code shorthand span ] trims the trailing characters while leaving the leading characters in place. For example, this removes the trailing spaces and newlines from the the string while leaving the leading characters alone

python
original = """

    echo foxtrot golf   

    """

right_stripped = original.rstrip()

print(f"START|{right_stripped}|END")
results start