Python问题:一段关于Palindrome的代码
def is_palindrome(s):
if type(s) != str:
return False
# base case before the or; recursive case after the or
if len(s) <= 1 or s[0] == s[-1] and is_palindrome(s[1: -1]):
return True
return False
strs = [False, 17, "", "a", "as", "ask", "ewe", "emma", "dromedary", "racecar"]
for s in strs:
print("%s --> %s" % (s, is_palindrome(s)))
请问 ispalindrome(s[1: -1]): 在 if len(s) <= 1 or s[0] == s[-1] and ispalindrome(s[1: -1]):当中起了什么作用?为什么是(s[1: -1])?