这是一个简单的程序
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"
我不知道从哪里得到这个错误。
答案 0 :(得分: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
""""
------^