osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how to get INDEX count, or last number of Index


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