判断字符串是否为回文 python
2024-08-24 05:05:37
回文正序和逆序一样的字符串,例如abccba
方法一
def is_palindrome1(text):
l = list(text)
l.reverse()
t1 = ''.join(l)
if t1 == text:
print 'the text is palindrome'
else:
print 'the text is not palindrome'
方法二
def is_palindrome2(text):
t1 = text[::-1]
if t1 == text:
print 'the text is palindrome'
else:
print 'the text is not palindrome'
方法三
def is_palindrome3(text):
r = True
for x in range(len(text)):
print x,text[x]
if text[x] != text[len(text)-x-1]:
print 1
r = False
break
if r == True:
print 'the text is palindrome'
else:
print 'the text is not palindrome'
最新文章
- MyBatis在insert插入操作时返回主键ID的配置
- MailKit系列之---查询SearchQuery
- Windows 7您的凭据不工作
- 移动端WEB开发备忘录
- 如何在CentOS 7上安装EPEL源
- java执行时的两个常见问题(无法加载主类)
- C++多态分析(polymorphisn)
- ext4.0绘制chart(柱状图,条形图)
- JS作用域概念-预解析规则
- 字符通向字节流的桥梁---- OutputStreamWriter
- eclipse扩容
- flask学习(一)
- Spring Cloud 2-Hystrix 断路容错保护(四)
- Mad Libs 游戏
- DatetimeHelper,时间帮助类
- Django异常问题之Error: [WinError 10013] 以一种访问权限不允许的方式做了一个访问套接字的尝试。
- CentOS7 yum 安装 PHP 5.6.24
- Centos7部署ntp服务器同步时间以及直接将本地时间同步为北京时间
- UE4中多种颜色轮廓线的后期处理
- Android-序列化-Serializable/Parcelable