What is the Python equivalent of Perl\'s chomp function, which removes the last character of a string if it is a newline?
chomp
>>> ' spacious '.rstrip() ' spacious' >>> "AABAA".rstrip("A") 'AAB' >>> "ABBA".rstrip("AB") # both AB and BA are stripped '' >>> "ABCABBA".rstrip("AB") 'ABC'