Slice last char from string without raising exception on empty string (Re: Extract all words that begin with x)

python at bdurham.com python at bdurham.com
Tue May 11 12:05:48 EDT 2010


Jerry,

> If you use negative indexes in the slice, they refer to items from the end of the sequence instead of the front. So slicing the last character from the string would be:
> 
> word[-1:]

Perfect! Thank you,

Malcolm



More information about the Python-list mailing list