1、用reduce函数方法
book = ‘Python程序设计‘ result = reduce(lambda x,y:y+x,book) print(result)
2、字符串切割
book = ‘Python程序设计‘ print(book[::-1])
3、用reversed方法,把字符串变成列表反转后拼接
result = reversed(list(book)) print(‘‘.join(result))
4、for循环
book = ‘Python程序设计‘ lenbook = len(book) - 1 result = ‘‘ for index,value in enumerate(book): result += book[lenbook - index] print(result)
目前只想到这些...
原文地址:https://www.cnblogs.com/fuxuhao/p/11963607.html
时间: 2024-10-05 05:37:07