how to get INDEX count, or last number of Index
Terry Reedy
tjreedy at udel.edu
Wed May 23 19:45:38 EDT 2018
On 5/23/2018 6:07 PM, asa32sd23 at gmail.com wrote:
> On Wednesday, May 23, 2018 at 5:51:42 PM UTC-4, asa3... 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, but i assume there is a function that gives me last number of index
>>
>> thanks
>
> thanks, it seems just a len(s) -1 is the right way to return it. thanks
No it is not. Just use -1
>>> s = 'kitty'
>>> s[len(s)-1]
'y'
>>> s[-1]
'y'
--
Terry Jan Reedy
More information about the Python-list
mailing list