This is an old copy of the Python FAQ. The information here may be
outdated.

Is there an equivalent to Perl's chomp() for removing trailing newlines from strings?

Starting with Python 2.2, rstrip lets you pass in what characters you want to remove from the end of a string. Use S.rstrip(“\r\n”) to remove all occurences of any line terminator from the end of the string S without removing other trailing whitespace. If the string S represents more than one line, with several empty lines at the end, the line terminators for all the blank lines will be removed: