Getting last char in string.

Daniel Dittmar daniel.dittmar at sap.com
Thu Sep 26 06:25:09 EDT 2002


CheapSkate wrote:
> then what does
> s[-1:] do?

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






More information about the Python-list mailing list