Prev: Slice last char from string without raising exception on empty string(Re: Extract all words that begin with x)
Next: Slice last char from string without raising exception on empty string (Re: Extract all words that begin with x)
From: superpollo on 11 May 2010 11:13 python(a)bdurham.com ha scritto: > Terry, > >> ... word[0:1] does the same thing. All Python programmers should learn to use slicing to extract a char from a string that might be empty. > > 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? > could it be: word[len(word)-1:] ? |