I have come across one question during where the person ask me
what is the output of this below code
Code :
names = ['Chris', 'Jack', 'John', 'Daman']
print(names[-1][-1])
Then i said the answer will be : John
But the person who was interviewing he said the answer is 'n'
Can some one illustrate how it is n
>Solution :
The [-1][-1] is not [-2] at all.
Take the last word, then its last letter
>> names
['Chris', 'Jack', 'John', 'Daman']
>> names[-1]
'Daman'
>> names[-1][-1]
'n' # 'n' of Daman
>> names[-1][-2]
'a' # last 'a' of Daman
>> names[0][1]
'h' # 'h' of Chris