How to trim n characters from right end of a string?

Tony Meyer t-meyer at ihug.co.nz
Sat Jun 26 20:03:06 EDT 2004


> >>> s = "This is a string"
> >>> s[:10]
> 'This is a '

Opps.  I guess you really wanted:

>>> s = "This is a string"
>>> s[:-6]
'This is a '

=Tony Meyer





More information about the Python-list mailing list