码迷,mamicode.com
首页 > 编程语言 > 详细

Python-判断回文

时间:2019-11-29 23:46:04      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:判断   lse   ==   pytho   print   pre   ati   for   方法   

# 回文单词是从左到右和从右到左读相同的单词。
# 例如:“detartrated”和“evitative”是回文


str_in = input('Input:')

#   方法一
count = 0
for i in range(len(str_in)):
    if str_in[i] == str_in[-i - 1]:
        count += 1

if len(str_in) == count:
    print('Yes')
else:
    print('No')

#   方法二
print('Yes') if str_in == str_in[::-1] else print('No')




Python-判断回文

标签:判断   lse   ==   pytho   print   pre   ati   for   方法   

原文地址:https://www.cnblogs.com/jiyu-hlzy/p/11960912.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!