No need for indices or lengths
def pal(w):
if w == "": return True
if w[0] != w[-1]: return False
return pal(w[1:-1])
but you may have been requested to use them...
Edit
Following a comment of the OP, that effectively narrows the spectrum of possible responses, here it is a look ma, no slices version of the above.
def pal(w, l=0, n=0):
# in production use: l = l if l else len(w)
if l ==0:
l = len(w)
print(("0123456789"*3)[:l])
print(w)
print(n, l-n-1, w[n], w[l-n-1])
if w[n] != w[l-n-1]: return False
if n+1 >= l-n-2: return True
return pal(w,l,n+1)
# a bit of testing
for word in ('aabbcbbaa', 'aabbccbbaa', 'aabbccbaa', 'aabbcdbbaa',
'saippuakivikauppias'):
print('Is the word "%s" palindrome? %s.' % (word, pal(word)))
The print expressions were used to show the work in progress of the function, the OP may want to remove them, as they were not requested (NB: w/o prints etc it's 5 LOC).
Output of testing
012345678
aabbcbbaa
0 8 a a
1 7 a a
2 6 b b
3 5 b b
Is the word "aabbcbbaa" palindrome? True.
0123456789
aabbccbbaa
0 9 a a
1 8 a a
2 7 b b
3 6 b b
4 5 c c
Is the word "aabbccbbaa" palindrome? True.
012345678
aabbccbaa
0 8 a a
1 7 a a
2 6 b b
3 5 b c
Is the word "aabbccbaa" palindrome? False.
0123456789
aabbcdbbaa
0 9 a a
1 8 a a
2 7 b b
3 6 b b
4 5 c d
Is the word "aabbcdbbaa" palindrome? False.
0123456789012345678
saippuakivikauppias
0 18 s s
1 17 a a
2 16 i i
3 15 p p
4 14 p p
5 13 u u
6 12 a a
7 11 k k
8 10 i i
Is the word "saippuakivikauppias" palindrome? True.
Final fireworks: the much expected one-liner
def pal(w): return 1 if w=="" else 0 if w[0]!=w[-1] else pal(w[1:-1])
nproblem, you have at least 2 other problems (1) you keep computing the length of the word, at every invocation of the function... it remains the same (2) you start comparing the first and the last character and go on up to compare the last character with the first... isn't there a bit of repetition?