python: recursive check to determine whether string is a palindrome

前端 未结 6 1321
死守一世寂寞
死守一世寂寞 2021-01-19 17:11

My task is to define a procedure is_palindrome, that takes as input a string, and returns a boolean indicating if the input string is a palindrome. In this case a single let

6条回答
  •  -上瘾入骨i
    2021-01-19 17:23

            is_palindrome(s[1:len(s)-1])
    

    needs to be...

            return is_palindrome(s[1:len(s)-1])
    

    in your first version, or

            result = is_palindrome(s[1:len(s)-1])
    

    in your second. Otherwise, you never actually propagate the recursive call's return value back to the original caller.

提交回复
热议问题