0

这是一个简单的程序

def is_palindrome_v1(s):
   """ (str) --> bool
   Return True if and only if s is a palindrome

   >>> is_palindrome_v1('noon')
   True
   >>> is_palindrome_v1('racecar')
   True
   >>> is_palindrome_v1('dented')
   False
   """"
   return reverse(s) == s

def reverse(s):
    """ (str) --> str
    Return a reversed version of s
    >>> reverse('hello')
    'olleh'
    >>> reverse('a')
    'a'
    """
    rev = ""
    for ch in s:
        rev = ch + rev
    return rev

我尝试运行时遇到的错误

"SyntaxError: EOL while scanning string literal"

不确定我从哪里得到这个错误。

4

1 回答 1

0

您的三引号字符串有一个"引号太多:

 """ (str) --> bool
   Return True if and only if s is a palindrome

   >>> is_palindrome_v1('noon')
   True
   >>> is_palindrome_v1('racecar')
   True
   >>> is_palindrome_v1('dented')
   False
   """"
------^
于 2013-04-14T13:21:42.107 回答