判断字符串是否为回文列表,不要reverse函数(一定要适合初学者哇)

img

s=list(input())
for i in range(len(s)):
if s[i]!=s[-(i+1)]:
print('不是回文')
break
else:
print('是回文')

涉及代码缩进,贴图。

img


#判断一个字符串是不是“回文”
def is_palindrome(s):
    lists = list(s)
    l = list(s)
    new_list = []
    for i in range(len(lists)):
        new_list.append(lists.pop())
    if new_list == l:
        return True
    else:
        return False

print(is_palindrome("abcdefgfedcba"))

img