Equivalent of Perl chomp?

Paul Rubin phr-n2002a at nightsong.com
Thu Jan 31 10:56:06 EST 2002


"Steve Holden" <sholden at holdenweb.com> writes:
> def chomp(s):
>     return s[:-1]

That's incorrect.  It's more like chop than chomp.  Closer would be:

def chomp(s):
   if s[-1]=='\n': return s[:-1]
   else: return s

However, chomp in perl actually changes the string, which can't be
done in Python.



More information about the Python-list mailing list