Repeated slicing works on tuples and lists just fine:
>>> tuple = ("nav", "yad")
>>> tuple[0]
'nav'
>>> tuple[0][0]
'n'
But with strings:
>>> name="university"
>>> name[0]
'u'
The weird thing here is, when I try repeated slicing over string name variable,
there is nothing at name[0][0] or name[0][-1], so why does it show "u"?
>>> name[0][0]
'u'
>>> name[0][-1]
'u'
And if something is at name[0][0] then why not on other indexes?
>>> name[0][1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: string index out of range
String is a sequence. String of one character is still a sequence with one element. So with a string you can do
name[0][0][0][0]...and it will work fine. Same with index-1, that returns last element of a sequence:name[0][1]obviously fails because there is only one element in the stringname[0].