On Tue, May 11, 2010 at 10:37 AM,  <pyt...@bdurham.com> wrote:
> Is there an equivalent way to slice the last char from a string (similar
> to an .endswith) that doesn't raise an exception when a string is empty?

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:]

-- 
Jerry
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to