how to get INDEX count, or last number of Index

Terry Reedy tjreedy at udel.edu
Wed May 23 19:44:50 EDT 2018


On 5/23/2018 5:56 PM, Rob Gaddi wrote:
> On 05/23/2018 02:51 PM, asa32sd23 at gmail.com wrote:
>> s = "kitti"
>>
>> 0,1,2,3,4
>> k,i,t,t,i
>>
>> how do i retrieve '4'. i know i can do a len(s)-1,

Use -1, which is the same as len(s)-1 but faster.

 >>> s = 'kitty'
 >>> s[len(s)-1]
'y'
 >>> s[-1]
'y'


-- 
Terry Jan Reedy




More information about the Python-list mailing list