python中实现字符串翻转的方法
作者:ListentTome 时间:2021-06-08 04:27:59
具体代码如下所示:
#字符串反转
def reverse (s):
rt = ''
for i in range(len(s)-1,-1,-1):
rt += s[i]
return rt
def reverse2 (s):
li = list(s)
li.reverse()
rt = "".join(li) return rt
def reverse3 (s):
return s[::-1]
def reverse4 (s):
return "".join(reversed(s))
from functools import reduce
def reverse5 (s):
return reduce(lambda x,y:y+x,s)
前两种是传统方法,后两种比较新颖
总结
以上所述是小编给大家介绍的python中字符串翻转的方法网站的支持!
来源:https://blog.csdn.net/ListentTome/article/details/81002611
标签:python,字符串,翻转
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python 怎么定义计算N的阶乘的函数
2021-04-12 01:44:04
![](https://img.aspxhome.com/file/2023/9/80659_0s.jpg)
Python模拟登录12306的方法
2023-03-11 09:12:36
30个最常用css选择器解析
2011-06-16 20:36:37
Django前后端分离csrf token获取方式
2021-03-15 04:23:43
![](https://img.aspxhome.com/file/2023/3/99143_0s.jpg)
Python基于百度AI实现OCR文字识别
2023-09-26 22:14:29
![](https://img.aspxhome.com/file/2023/3/90503_0s.png)
Python基于动态规划算法计算单词距离
2021-09-18 11:18:16
python3爬取淘宝信息代码分析
2021-05-03 04:59:11
JS轮播图中缓动函数的封装
2023-08-22 20:50:11
Python绘制交通流折线图详情
2023-04-29 01:26:36
![](https://img.aspxhome.com/file/2023/2/86652_0s.png)
java.sql.SQLException: 内部错误: Unable to construct a Datum from the specified input
2010-07-16 13:23:00
详解pyqt5 动画在QThread线程中无法运行问题
2021-07-22 21:00:43
![](https://img.aspxhome.com/file/2023/9/99539_0s.gif)
np.newaxis 实现为 numpy.ndarray(多维数组)增加一个轴
2021-02-14 07:48:20
Python使用描述符实现属性类型检查的案例解析
2022-07-30 00:39:15
selenium中常见的表单元素操作方法总结
2021-06-15 23:54:32
![](https://img.aspxhome.com/file/2023/0/95320_0s.jpg)
Python实现OCR识别之pytesseract案例详解
2021-03-02 02:14:35
![](https://img.aspxhome.com/file/2023/2/94702_0s.png)
小谈用户身体语言的阅读经验
2009-10-19 20:52:00
![](https://img.aspxhome.com/file/UploadPic/200910/19/bodylanguage-banner-72s.jpg)
python解决字符串倒序输出的问题
2022-06-08 14:12:34
django基础学习之send_mail功能
2023-04-01 00:16:53
python实现隐马尔科夫模型HMM
2023-05-05 13:33:57
Python摸鱼神器之利用树莓派opencv人脸识别自动控制电脑显示桌面
2021-01-12 07:31:45
![](https://img.aspxhome.com/file/2023/1/97531_0s.jpg)