indexing in format strings

Terry Reedy tjreedy at udel.edu
Fri Apr 11 22:44:04 EDT 2014


On 4/11/2014 7:13 PM, blindanagram wrote:
> On 11/04/2014 22:33, blindanagram wrote:
>
> Thanks, Mark and Terry, for your rapid responses.
>
> An interesting thread.

It just occurred to me today, and I verified, that '+1' is also seen as 
a string.

 >>> '{0[-1]}'.format({'-1': 'neg int key'})
'neg int key'
 >>> '{0[+1]}'.format({'+1': 'neg int key'})
'neg int key'
 >>> '{0[+1]}'.format([1,2,3])
Traceback (most recent call last):
   File "<pyshell#16>", line 1, in <module>
     '{0[+1]}'.format([1,2,3])
TypeError: list indices must be integers, not str


-- 
Terry Jan Reedy




More information about the Python-list mailing list