Getting last char in string.

CheapSkate gua81 at XXXyahoo.com
Thu Sep 26 07:15:03 EDT 2002


"Daniel Dittmar" <daniel.dittmar at sap.com> wrote in message
news:amuna6$erv$1 at news1.wdf.sap-ag.de...
> >>> s = ''
> >>> s [-1]
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> IndexError: string index out of range
> >>> s [-1:]
> ''
> s [-1] returns a single element, s [-1:] returns a sequence. But in the
> current Python definition (implementation?), single characters are strings
> of length 1.
>
> Daniel

if s[-1] returns a single element, why woulnd't it return " ?
Single character are strings of length 1(as u said) and " is single
character right?





More information about the Python-list mailing list