我们专注孝感网站设计 孝感网站制作 孝感网站建设
成都网站建设公司服务热线:18982081108

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

创新互联Python教程:python字符串的翻转实现的两种方法

python字符串的翻转实现的两种方法 

方法一:利用切片

str1 = "hello world!"
print(str1[::-1])

方法二:利用reduce函数实现

from functools import reduce
str1 = "hello world!"
print(reduce(lambda  x, y : y+x, str1))

补充:判断字符串是不是回文串

str1 = "123455"
def fun(string):
    print("%s" % string == string[::-1] and "YES" or "NO")
if __name__ == '__main__':
    fun(str1)

新闻标题:创新互联Python教程:python字符串的翻转实现的两种方法
转载来于:http://www.ytofo.com/article/djegcph.html

其他资讯