You can use the rstrip() method to remove a trailing newline from a string. Here is an example:
This will print "Hello, World!" (without the newline).
Alternatively, you can use the strip() method to remove both leading and trailing whitespace, including newlines. For example:
This will also print "Hello, World!" (without the leading spaces or the newline).
Got an article suggestion?
Let us know
BY
NC
SA
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.