Newbie asks, how to get rid of the last four characters of a string?

Roy Smith roy at panix.com
Wed Jan 22 15:56:38 CET 2003


Christopher Culver <kricxjo.neniuspamajxo at yahoo.com> wrote:
> is there a function that can be used to chomp off the last four
> characters without having to import the re module?

Look up the slice operator in the manual.  For example:

>>> filename = "mySillyFilename.doc"
>>> filename[:-4]
'mySillyFilename'




More information about the Python-list mailing list