What is the Python equivalent of Perl\'s chomp function, which removes the last character of a string if it is a newline?
chomp
s = s.rstrip()
will remove all newlines at the end of the string s. The assignment is needed because rstrip returns a new string instead of modifying the original string.
s
rstrip