How to trim n characters from right end of a string?
Tony Meyer
t-meyer at ihug.co.nz
Sat Jun 26 19:55:07 EDT 2004
> Please tell this newbie how to remove n characters from the
> right end of a string.
You can't - Python strings are immutable. You can, however, create a new
string that is the same as the old one less the n rightmost characters,
which should do what you need.
>>> s = "This is a string"
>>> s[:10]
'This is a '
The tutorial on strings would be well worth reading to help with this sort
of thing.
=Tony Meyer
More information about the Python-list
mailing list