How can I remove a trailing newline in Python?

If you are looking to remove space or newline from a string in Python, use strip(), lstrip(), or rstrip() methods in Python as shown in the below examples –

Remove a trailing newline in Python

Remove trailing whitespace in Python

Similarly, you can use lstrip() to remove newline and whitespace from the beginning of a string in Python –

Leave a Reply

Close Menu