Can someone explain me the difference between these two codes?
def pal(s):
if s == "":
return True
if s[0] != s[-1]:
return False
return pal(s[1:-1])
a = "anna"
print(pal(a))
and
def pal(s):
if s == "":
return True
if s[0] != s[-1]:
return False
pal(s[1:-1])
a = "anna"
print(pal(a))
Why the firts one return the right value, that is True
, and the second return me None
?